2012-02-24 36 views
0

我想串T和字符串的值賦給b要R.layout.news_01story 宣佈兩個TextView的可以這樣做?需要幫助!在Android編程中將字符串值分配給TextViews?

波紋管的方法把我們帶到一個新的佈局,當我們在ListView單擊項目 - >

@Override 
public void onListItemClick(ListView parent, View v, int position, long id) { 
    CustomAdapter adapter = (CustomAdapter) parent.getAdapter(); 
     RowData row = adapter.getItem(position); 
     String t = row.mTitle; 
     String b = row.mDescription; 

     AlertDialog.Builder builder=new AlertDialog.Builder(this); 
     LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); 
     View layout = inflater.inflate(R.layout.news_01story,null); 
     builder.setView(layout); 
     builder.show(); 
} 

商祺!

回答

0
.... 
View layout = inflater.inflate(R.layout.news_01story,null); 
TextView textView1 = (TextView)layout.findViewById(R.id....); 
textView.setText(t); 
TextView textView2 = (TextView)layout.findViewById(R.id....); 
textView.setText(b); 
.... 
+0

這個作品有輕微的變化...感謝您的幫助! – 2012-02-24 11:35:26

0

只需使用

((TextView)layout.findViewById(R.id.text_view_1)).setText(t); 
((TextView)layout.findViewById(R.id.text_view_2)).setText(b); 
+0

GR8!感謝您的幫助 – 2012-02-24 11:34:55

+0

http://meta.stackexchange.com/a/5235/176901 – Jin35 2012-02-24 11:57:40