简体   繁体   中英

TextView update not happening when selected item from ListView

Hi I have Listview in that when I select an item I display another page where I am setting the text views with appropriate informations but when i select an item and go back and select another item the textviews are not getting updated ?BTW there are 10 text views can somebody provide me the solution for this? Thanks.

    super.onCreate(savedInstanceState);
    setContentView(R.layout.lastl);

    Intent i = getIntent();
    ACK = i.getStringExtra("ack-no");
    NAME = i.getExtras().getString("appl name");
    TRADE = i.getExtras().getString("trade");
    PIN = i.getExtras().getString("pin");
    MOBILE = i.getExtras().getString("mobile");
    EMAIL = i.getExtras().getString("email");
    LVO1 = i.getExtras().getString("LVO1");
    LVO2 = i.getExtras().getString("LVO2");

    tv1 = (TextView) findViewById(R.id.set_ack);
    tv1.setText(ACK);
    tv2 = (TextView) findViewById(R.id.set_apl);
    tv2.setText(NAME);
    tv3 = (TextView) findViewById(R.id.set_trd);
    tv3.setText(TRADE);
    tv4 = (TextView) findViewById(R.id.set_dr);
    tv4.setText(ArrayAdapter.ar.get(0));
    tv5 = (TextView) findViewById(R.id.set_flr);
    tv5.setText(ArrayAdapter.ar.get(1));
    tv6 = (TextView) findViewById(R.id.set_bdg);
    tv6.setText(ArrayAdapter.ar.get(2));
    tv7 = (TextView) findViewById(R.id.set_str);
    tv7.setText(ArrayAdapter.ar.get(3));
    tv8 = (TextView) findViewById(R.id.set_area);
    tv8.setText(ArrayAdapter.ar.get(4));
    tv9 = (TextView) findViewById(R.id.set_dis);
    //tv9.setText(ArrayAdapter.ar.get(5));
    tv10 = (TextView) findViewById(R.id.set_pin);
    tv10.setText(PIN);
    tv11 = (TextView) findViewById(R.id.set_mb);
    tv11.setText(MOBILE);
    tv12 = (TextView) findViewById(R.id.set_email);
    tv12.setText(EMAIL);
    tv13 = (TextView) findViewById(R.id.set_pn);
    tv14 = (TextView) findViewById(R.id.set_bdgg);
    tv15 = (TextView) findViewById(R.id.set_dt);
    tv16 = (TextView) findViewById(R.id.set_lvo);
    tv16.setText(LVO1);

    String lvo2 = LVO2.substring(0, LVO2.length() - 1);
    Log.d("sssssss", lvo2);

    tv17 = (TextView) findViewById(R.id.set_lvo2);
    tv17.setText(lvo2);

    b1 = (Button) findViewById(R.id.button1);
    b1.setOnClickListener(this);
    b2 = (Button) findViewById(R.id.button2);
    b2.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.button1:
            break;
        case R.id.button2:
            break;
    }
}

this is my listView code

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listmain);

    pv = getIntent().getStringArrayListExtra("Array_list");
    System.out.println("ARRAYLIST---->" + pv);

    final ListView list = (ListView) findViewById(R.id.listView1);
    mylistData = new ArrayList<HashMap<String, String>>();

    String[] columnTags = new String[]{"col1", "col2", "col3", "col4", "col5", "col6", "col7", "col8"};

    int[] columnIds = new int[]{R.id.col1, R.id.col2, R.id.col3, R.id.col4, R.id.col5, R.id.col6, R.id.col7, R.id.col8};

    int k = 0;
    for (int i = 0; i <= 9; i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        //initialize row data
        for (int j = 0; j <= 7/*pv.size()-1*/; j++) {
            map.put(columnTags[j], pv.get(k));
            put(columnTags[j], "row" + i + "col" + j);
            k++;
        }

        mylistData.add(map);
    }

    SimpleAdapter arrayAdapter = new SimpleAdapter(this, mylistData, R.layout.rowmain, columnTags, columnIds);
    list.setAdapter(arrayAdapter);

    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parnet, android.view.View view, int position, long id) {
            new LongOperation().execute();

            String text = list.getItemAtPosition(position).toString();
            String g = text.replace("{col5=", "");
            String g1 = g.replace(" col4=", "");
            String g2 = g1.replace(" col7=", "");
            String g3 = g2.replace(" col6=", "");
            String g4 = g3.replace(" col1=", "");
            String g5 = g4.replace(" col3=", "");
            String g6 = g5.replace(" col2=", "");
            String g7 = g6.replace(" col8=", "");

            String val[] = g7.split(",");

            for (int m = 0; m < val.length; m++) {
                Log.d("VALUE", val[m]);
                ar1.add(val[m]);
            }

            System.out.println(ar1);

            Log.d("VALUES-------->", text);
            mob = ar1.get(0);
            Log.d("VALUE1", mob);
            pin = ar1.get(1);
            Log.d("VALUE2", pin);
            lvo = ar1.get(2);
            Log.d("VALUE3", lvo);
            email = ar1.get(3);
            Log.d("VALUE4", email);
            ack = ar1.get(4);
            Log.d("VALUE5", ack);
            trade = ar1.get(5);
            Log.d("VALUE6", trade);
            name = ar1.get(6);
            Log.d("VALUE7", name);
            lvo2 = ar1.get(7);
            Log.d("VALUE8", lvo2);
        }
    });
}

From your code: ar1.add(val[m]);
I guess that ar1 is a List<String> variable of your listview activity?
If that's true, maybe add a call to clear() may work:

ar1.clear();
for(int m =0 ; m< val.length ; m++)
{
  Log.d("VALUE",val[m]);
  ar1.add(val[m]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM