Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling getView() method in custom ListView
    text
    copied!<p>I am using custom <code>ListView</code> with text and arrow image at right of the list row.</p> <p>I have the following</p> <blockquote> <p>1: MainActivity extends ListActivity</p> <p>2: SpecialAdapter extends ArrayAdapter have getView() method.</p> <p>3: classes for Sqlite Database.</p> </blockquote> <p>I have an <code>EditText</code> and add <code>Button</code> for storing new text into database as well as to my list. Code is here.</p> <pre><code> OnClickListener listenerAdd = new OnClickListener() { @Override public void onClick(View v) { Comment comment = null; EditText edit = (EditText) findViewById(R.id.edit_txt); String number = edit.getText().toString(); if(!number.equals("")){ comment = datasource.createComment(number); adapter.add(comment); edit.setText(""); adapter.notifyDataSetChanged(); } else{ Toast.makeText(getApplicationContext(), "Please enter a Number",Toast.LENGTH_SHORT).show(); } } }; </code></pre> <p>I am totally confused that in which class I should use this code?</p> <p>How to call getView method?</p> <p>I used this code in main class but it throws exception. </p> <p>The more important is what adapter I should to use?</p> <p>Adapter Code here..</p> <pre><code> public class SpecialAdapter extends ArrayAdapter&lt;Comment&gt;{ Context context; int layoutResourceId; Comment data[]= null; // Comment dataCom[] = null; public SpecialAdapter(Context context, int layoutResourceId,Comment[] values) { super(context, layoutResourceId, values); this.layoutResourceId = layoutResourceId; this.context = context; this.data = values; } @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; WeatherHolder holder = null; if(row == null) { LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, parent, false); holder = new WeatherHolder(); holder.imgIcon = (ImageView)row.findViewById(R.id.img_arrow); holder.txtTitle = (TextView)row.findViewById(R.id.tv_number); row.setTag(holder); } else { holder = (WeatherHolder)row.getTag(); } Comment comment = data[position]; holder.txtTitle.setText(comment.getComment()); holder.imgIcon.setImageResource(R.drawable.arrow); return row; } static class WeatherHolder { ImageView imgIcon; TextView txtTitle; } } </code></pre>
 

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