Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting TextView text color in a listview gives color to random textviews while scrolling?
    primarykey
    data
    text
    <p>Everything works fine till I dont scroll.As soon as I scroll down other TextView get the color randomly.Here is my code.</p> <pre><code> public View getView(final int position, View convertView, ViewGroup parent) { // ViewHolder holder = null; View row = convertView; if(row==null){ LayoutInflater inflater=getLayoutInflater(); row=inflater.inflate(R.layout.prices_list, parent, false); } item = (TextView)row.findViewById(R.id.textView1); item.setText(items[position]); price = (TextView)row.findViewById(R.id.textView2); price.setText(prices[position]); cprice=(Button)row.findViewById(R.id.button1); cprice.setTag(position); cprice.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub RelativeLayout rl = (RelativeLayout)v.getParent(); TextView tv1=(TextView)rl.findViewById(R.id.textView1); TextView tv2=(TextView)rl.findViewById(R.id.textView2); create(tv2.getText().toString(),tv2,tv1.getText().toString(),position); } }); return row; } } create function: public void create(String price, final TextView tv1,final String item,final int position) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Update Prices"); builder.setMessage("Current Price "+price); // Use an EditText view to get user input. final EditText input = new EditText(this); builder.setView(input); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { uvalue = input.getText().toString(); tv1.setText(uvalue); item_value[count]=uvalue; prices[position]=uvalue; item_name[count]=item; updated[count]=tv1; DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(getApplicationContext()); try { dbAdapter.createDataBase(); } catch (IOException e) { } dbAdapter.openDataBase(); try { String query = "UPDATE Prices SET Price="+item_value[count]+" where Item_Name='"+item_name[count]+"'"; Log.i("TAG","Query executed"); Cursor c = dbAdapter.selectRecordsFromDB(query, null); ContentValues cv= new ContentValues(); cv.put("Price", item_value[count]); Log.i("TAG","value to be updated is"+item_value[count]); Log.i("TAG","Item to be updated is"+item_name[count]); boolean c1= dbAdapter.updateRecordInDB("Prices", cv, "Item_Name='"+item_name[count]+"'", null); count++; if(c1) tv1.setTextColor(Color.YELLOW); } catch (Exception e) { e.printStackTrace(); } dbAdapter.close(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); builder.show(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload