选择特定项目并提供保存的数据

时间:2012-12-04 09:36:25

标签: java android android-intent

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

我的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();


           }

}

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

2 个答案:

答案 0 :(得分: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);
}

答案 1 :(得分:0)

您可以使用SharedPreferences

来完成此操作