我有一個listview class.listview打開,用戶可以單擊任何listview項目。我想在xml上設置文本。我有像st1-st2-st3這樣的字符串。如果我點擊任何列表視圖項目,我怎麼能得到它打開xml和設置Textview1爲st1/@字符串?用意圖(字符串)更改TextView
我的listview像這樣工作;
public class strateji extends Activity {
private static final String LOG_TAG = "Alert Dialog Activity";
private ListView lv1;
private TextView status;
private String lv_arr[]={"listview1-list2-list3-list4-list5-list6-etc..."};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ana);
// Look up the AdView as a resource and load a request.
Log.i(LOG_TAG, "Alert Dialog Activity Started");
lv1=(ListView)findViewById(R.id.listView1);
// By using setAdpater method in listview we an add string array in list.
lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr));
lv1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if(position == 0)
{
setContentView(R.layout.texts); //--->opening texts.xml and setText
status.setText(String);--------->>> like this i want send a string for TextView
}
if(position == 1)
{
Intent myIntent = new Intent(strateji.this, mat2.class);
startActivityForResult(myIntent, 0);
}
}
}
'texts'是TextView的內部'ana'佈局或在不同的佈局? – 2014-10-01 19:46:52
你的問題並不清楚。你想設置一個ListView項目的文本,或者在一個單獨的活動佈局? – cYrixmorten 2014-10-01 19:56:22
沒有用戶會點擊一個列表視圖項目和列表視圖項目將發送一個字符串到任何textview.Textview將是一個XML。 – MacSTD 2014-10-01 19:57:30