Note that there are some explanatory texts on larger screens.

plurals
  1. POchange custom listview item
    primarykey
    data
    text
    <p>Infact i have a listview and it has "two images + two Textviews" as an item.</p> <p>What i exactly want to do is that i want to change the textview's text when user clicks the image.</p> <p><code>public class ListViewCustomAdapter extends BaseAdapter implements OnClickListener{</code></p> <pre><code>`ViewHolder holder;` `ArrayList&lt;Object&gt; itemList;` `public Activity context;` `public LayoutInflater inflater;` `public ListViewCustomAdapter(Activity context,ArrayList&lt;Object&gt; itemList) {` `super();` `this.context = context;` `this.itemList = itemList;` `this.inflater =` `(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);` `}` `@Override` `public int getCount() {` `// TODO Auto-generated method stub` `return itemList.size();` `}` `@Override` `public Object getItem(int position) {` `// TODO Auto-generated method stub` `return itemList.get(position);` `}` `@Override` `public long getItemId(int position) {` `// TODO Auto-generated method stub` `return 0;` `}` `public static class ViewHolder` `{` `ImageView plus;` `ImageView minus;` `TextView question;` `TextView score;` `}` `@Override` `public View getView(int position, View convertView, ViewGroup parent) {` `// TODO Auto-generated method stub` `if(convertView==null)` `{` `holder = new ViewHolder();` `convertView = inflater.inflate(R.layout.listitem_row, null);` `holder.plus = (ImageView) convertView.findViewById(R.id.plus);` `holder.minus = (ImageView) convertView.findViewById(R.id.minus);` `holder.plus.setOnClickListener(this);` `holder.minus.setOnClickListener(this);` `holder.question = (TextView) convertView.findViewById(R.id.question);` `holder.score = (TextView) convertView.findViewById(R.id.score);` `convertView.setTag(holder);` `}` `else` `holder=(ViewHolder)convertView.getTag();` `ItemBean bean = (ItemBean) itemList.get(position);` `holder.minus.setImageResource(bean.getminus());` `holder.plus.setImageResource(bean.getplus());` `holder.question.setText(bean.getquestion());` `holder.score.setText(bean.getscore());` `return convertView;` `}` `@Override` `public void onClick(View v) {` `switch(v.getId()) {` `case R.id.minus:` `{` `int score = Integer.getInteger(holder.score.getText().toString());` `holder.score.setText(Integer.toString(score-1));` `break;` `}` `case R.id.plus:` `{` `int score = Integer.getInteger(holder.score.getText().toString());` `holder.score.setText(Integer.toString(score+1));` `break;` `}` `}}` </code></pre> <p><code>}</code></p> <p>I am getting null pointer exception. What i think the problem is, program is not able to understand that which textview it sould target, like there are multiple items in this listview, and each item contains this Score Textview item. </p> <p>Plz help me out!!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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