Pregunta

Actually Am New to Android .Am having list of items in listview. If I click particular row in listview. I want to get particular value in edittext. For Example..

1

Raj

Chennai

2

Ram

Coimbatore

from this listview .if i click first Row of listview..That RAJ name will get in edittext..

Please help me anyone.. thanks in advance

This is my listview adapter.

private class JSONParse extends 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);
¿Fue útil?

Solución

Try this.. it will works.

How to get the value of a Listview item which is clicked in android?

How to get TextView values from a listView Items?

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

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


                String my_value = jobNo.getText().toString();

            }
        });

Otros consejos

If you're new to Android you should probably take a look at this tutorial:

http://www.vogella.com/tutorials/AndroidListView/article.html#listview_adapterlistener

It gives you a good impression on how to work with listviews. You may also find useful information about how to use custom adapters...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top