Note that there are some explanatory texts on larger screens.

plurals
  1. POlistView doesn't get filled?
    text
    copied!<p>I'm trying to do an app with listView, which is need to be filled from another class... I'm basicly follow this site: <a href="http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/" rel="nofollow">http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/</a> but somehow my adapter doesn't work right... And do not fill my listView... </p> <p>I create a new object from my main class like: fillLeftMenu lmenu = new fillLeftMenu(menu);</p> <p>I used this line for having started the activity, if it's not wrong:</p> <pre><code>startActivity(new Intent("com.yahya.training.FILLLEFTMENU")); </code></pre> <p>On my AndroidManifest.xml, i added this following lines:</p> <pre><code> &lt;activity android:name=".fillLeftMenu" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="com.yahya.training.FILLLEFTMENU" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; </code></pre> <p>And the fillLeftMenu class is:</p> <pre><code>public class fillLeftMenu extends ListActivity { private ProgressDialog myProgressDialog = null; private View menu; ImageView findLocation; Spinner cityList; ListView leftList; String [] textIndex; Drawable [] imageIndex; ArrayList&lt;LeftListItems&gt; Left; listAdapter lAdapter; public fillLeftMenu(View Lmenu) { this.menu = Lmenu; } public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); findLocation = (ImageView) menu.findViewById(R.id.image_findLocation); leftList = (ListView) menu.findViewById(R.id.list); // add items to listView Left = new ArrayList&lt;LeftListItems&gt;(); textIndex = new String[] {"Bugünün Fırsatları", "Son Dakika Bonusları", "Kadın", "Aile", "Çocuk", "Alışveriş", "Şehirden Kaçış", "Kışa Özel"}; imageIndex = new Drawable[] {leftList.getResources().getDrawable(R.drawable.kucukicon_01),leftList.getResources().getDrawable(R.drawable.kucukicon_02),leftList.getResources().getDrawable(R.drawable.kucukicon_03),leftList.getResources().getDrawable(R.drawable.kucukicon_04),leftList.getResources().getDrawable(R.drawable.kucukicon_05),leftList.getResources().getDrawable(R.drawable.kucukicon_06),leftList.getResources().getDrawable(R.drawable.kucukicon_07),leftList.getResources().getDrawable(R.drawable.kucukicon_08)}; lAdapter = new listAdapter(menu.getContext(), R.layout.list_item, Left); leftList.setAdapter(lAdapter); Runnable viewOrders = new Runnable(){ public void run() { getIndex(); } }; Thread thread = new Thread(null, viewOrders, "MagentoBackground"); thread.start(); myProgressDialog = ProgressDialog.show(fillLeftMenu.this,"Please wait...", "Retrieving data ...", true); leftList.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { } }); } private Runnable returnRes = new Runnable() { public void run() { if(Left != null &amp;&amp; Left.size() &gt; 0){ lAdapter.notifyDataSetChanged(); for(int i=0;i&lt;Left.size();i++) lAdapter.add(Left.get(i)); } myProgressDialog.dismiss(); lAdapter.notifyDataSetChanged(); } }; private void getIndex() { try{ LeftListItems item = new LeftListItems(); for(int i=0; i&lt;textIndex.length; i++) { item.setText(textIndex[i]); item.setImage(imageIndex[i]); Left.add(item); } } catch (Exception e) { Log.e("BACKGROUND_PROC", e.getMessage()); } runOnUiThread(returnRes); } private class listAdapter extends ArrayAdapter&lt;LeftListItems&gt; { private ArrayList&lt;LeftListItems&gt; items; private Context ctx; public listAdapter(Context ctx, int textViewResourceId, ArrayList&lt;LeftListItems&gt; items) { super(ctx, textViewResourceId, items); this.ctx = ctx; this.items = items; } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { // LayoutInflater inflater = LayoutInflater.from(ctx); // v = inflater.inflate(R.layout.list_item, null); LayoutInflater vi = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.list_item, null); } LeftListItems index = items.get(position); if(index != null) { TextView text = (TextView) v.findViewById(R.id.text); ImageView img = (ImageView) v.findViewById(R.id.icon); if(text != null) text.setText(index.getText()); if(img != null) img.setBackgroundDrawable(index.getImage()); } return v; } } } </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