2

我的项目中有 ListView,它的 ListItems 像这样的 String 形式,

到今天完成任务
分配项目给开发人员
会议取消

如果单击 ListView 中的任何一项,则意味着我希望该特定字符串应显示在我的 EditText 中(即,如果单击会议取消,我需要此特定字符串显示在 EditText 中)。任何人都可以指导我,这就是我的方式'我正在尝试在此处实现。在此输入代码在此先感谢。

final ListView listView = (ListView) findViewById(R.id.taskListDesc); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View view, int selectedItem,
                long arg3) {

            System.out.println(adapter.getItemAtPosition(selectedItem));

            Intent intent = new Intent(getApplicationContext(),
                    ViewTaskActivity.class);
            startActivity(intent);
        }
    });
}
4

2 回答 2

7
ArrayAdapter<String> adapter;

adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item, profielNames); 
setListAdapter(adapter);

 @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {

  super.onListItemClick(l, v, position, id);

  // Get the data associated with selected item
  Object item = l.getItemAtPosition(position);
  String myitem = item.toString();
  edittxt.setText("Selected item is :"+ myitem); // You can Set EditText from Here.
 }
于 2012-04-05T05:57:03.170 回答
2

你甚至可以试试这个......

public class ExampleActivity extends Activity {

String str_arr[] = {"A", "B", "C"};


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ListView listView = (ListView) findViewById(R.id.listView1);

    listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, str_arr));

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View view, int position,
                long id) {
            // TODO Auto-generated method stub
            Object o = adapter.getItemAtPosition(position);
            String str_text = o.toString();

            Intent intent = new Intent(ExampleActivity.this, NewExample.class);
            intent.putExtra("StrValue", str_text);
            startActivity(intent);
        }

    });
 }
 }

public class NewExample extends Activity {

EditText editText;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newmain);

    editText = (EditText) findViewById(R.id.editText1);

    String value = getIntent().getStringExtra("StrValue").toString();

    editText.setText(value);
}

}

希望这可以帮助.......

Njoy编码......

于 2012-04-05T08:44:53.013 回答