实际上我是 Android 的新手。我在 ListView 中有项目列表。如果我单击 ListView 中的特定行。我想在 edittext 中获得特定的值(value)。 例如..
1
拉吉
金奈
2
拉姆
哥印拜陀
从这个listview。如果我单击 listview 的第一行..那个RAJ 名称将进入edittext..
请任何人帮助我..提前致谢
这是我的 ListView 适配器。
私有(private)类 JSONParse 扩展了 AsyncTask {
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
DateTime = (TextView)findViewById(R.id.textView1);
Status = (TextView)findViewById(R.id.textView2);
JobNo = (EditText) findViewById(R.id.add_JobNo);
//Status = (EditText) findViewById(R.id.add_Status);
//DateTime = (EditText) findViewById(R.id.add_Date_Time);
pDialog = new ProgressDialog(Add_Update_User.this);
pDialog.setMessage("Processing Please Wait ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected JSONObject doInBackground(String... args) {
JSONParser jParser = new JSONParser();
String flag="S" ;
ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.clear();
params.add(new BasicNameValuePair("JobNo",JobNo.getText().toString()));
params.add(new BasicNameValuePair("flag",flag));
//Getting JSON from URL
JSONObject json = jParser.getJSONFromUrl(url,params);
return json;
}
protected void onPostExecute(JSONObject json) {
pDialog.dismiss();
try {
if (JobNo.getText().toString().equals("") )
{
Toast.makeText(Add_Update_User.this, "The Field Should not be null", Toast.LENGTH_SHORT).show();
}
else
{
// Getting JSON Array from URL
Cargo = json.getJSONArray(TAG_CargoTrack);
for(int i = 0; i < Cargo.length(); i++){
JSONObject c = Cargo.getJSONObject(i);
String JobNo = c.getString(TAG_JobNo);
String Status = c.getString(TAG_Status);
String Datetime = c.getString(TAG_DateTime);
// Adding value HashMap key => value
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_JobNo, JobNo);
map.put(TAG_Status, Status);
map.put(TAG_DateTime, Datetime);
CargoTracklist.add(map);
list=(ListView)findViewById(R.id.listView1);
//SimpleAdapter adapter = new SimpleAdapter(Add_Update_User.this, CargoTracklist,
ListAdapter adapter = new SimpleAdapter(Add_Update_User.this, CargoTracklist,
R.layout.search,
new String[] { TAG_JobNo,TAG_Status, TAG_DateTime }, new int[] {
R.id.user_JobNo_txt,R.id.user_Status_txt, R.id.user_Date_Time_txt });
list.setAdapter(adapter);
最佳答案
试试这个..它会起作用。
How to get the value of a Listview item which is clicked in android?
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,
long arg3) {
String my_value = jobNo.getText().toString();
}
});
关于android - 如果我从 ListView 中单击特定行,如何在 Edittext 中获取特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23307451/