2

在我的应用程序中,我希望当我从列表中选择一个特定项目时,它会给出它的保存数据,因为每个项目都是一个包含一些数据的字段。我怎样才能做到这一点???

我的Java代码是:

 public void Onclick_click4(final TextView task_detail_txt)
{
    final TextView txtbox = (TextView) task_detail_txt ;

    if(task_detail_txt.getId()==R.id.textView4)
    {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Task Details");

        ListView modeList = new ListView(this);
        final String[] stringArray = new String[] { "Ticket Number", "Job Performed", "Date and Time", "GPS-Latitude", "GPS-Longitude", "Status", "Next Due on" };
        ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, stringArray);
        modeList.setAdapter(modeAdapter);

        builder.setItems(stringArray, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                 Toast.makeText(getApplicationContext(), stringArray[item], Toast.LENGTH_SHORT).show();
                 txtbox.setText(stringArray[item]);
                 System.out.println("Item is: "+stringArray[item]);
                 /*CONTRY_ID = con.get(item).getCountryId();
                 stateET.requestFocus();*/
            }
         });


    builder.show();


           }

}

正如我想要的那样,当我点击票号时,它会给我保存在另一个活动中的号码。ETC

4

2 回答 2

0

您可以使用SharedPreferences来做到这一点

于 2012-12-04T09:46:21.813 回答
0

如果你扩展ListActivity,你可以覆盖onListItemClick,并以这种方式检索数据:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    ArrayAdapter<String> adpter = (ArrayAdapter<String>)l.getAdapter();
    String data = l.getItem(position);
}
于 2012-12-04T09:41:12.150 回答