Note that there are some explanatory texts on larger screens.

plurals
  1. POadding items to custom listview only displays new items on touch
    primarykey
    data
    text
    <p>I am adding items to a ListView dynamically and i have the Problem that new Entries only get displayed when i touch the screen of the phone.</p> <p>I am using this code to add a new item:</p> <pre><code>public TimerTask tt = new TimerTask() { @Override public void run() { LoadChatData bdl = new LoadChatData(new OnTaskComplete() { @Override public void onTaskCompleted(ArrayList&lt;ChatListItem&gt; item, int id) { currid = id; for (ChatListItem i : item) { dataarr.add(i); } chatList.notifyDataSetChanged(); } }); bdl.execute(XXX); } }; </code></pre> <p>chatList is the adapter and dataarr the Data which the adapter holds. The entries gets added but only when i touch the phone screen they get shown.</p> <p>My custom Adapter looks like this:</p> <pre><code>import java.util.ArrayList; import android.content.Context; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.RelativeLayout; import android.widget.TextView; public class ChatList extends BaseAdapter { java.util.List&lt;ChatListItem&gt; data = null; Context context; int layoutResourceId; public String me = null; public void setId(String aid){ this.me = aid; } public ChatList(Context context, int layoutResourceId, ArrayList&lt;ChatListItem&gt; data) { this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; } @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; ChatHolder holder = null; ChatListItem entry = data.get(position); if (row == null) { LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(layoutResourceId, parent, false); holder = new ChatHolder(); holder.txtText = (TextView) row.findViewById(R.id.txtText); holder.txtUser = (TextView) row.findViewById(R.id.txtUser); holder.txtVersion = (TextView) row.findViewById(R.id.txtVersion); holder.txtZeit = (TextView) row.findViewById(R.id.txtZeit); holder.background = (RelativeLayout) row.findViewById(R.id.backgroundlayout); row.setTag(holder); } else { holder = (ChatHolder) row.getTag(); } int status = Integer.parseInt(entry.status); /* * android:paddingBottom="5dp" android:paddingLeft="5dp" * android:paddingRight="15dp" android:paddingTop="5dp" */ if (entry.uid.equals(me)) { holder.background.setPadding(20, 5, 30, 5); holder.background.setBackgroundResource(R.drawable.chatitem_me); } else { holder.background.setPadding(30, 5, 20, 5); holder.background.setBackgroundResource(R.drawable.chatitem); } holder.txtUser.setTextColor(0xFF000000); holder.txtText.setTextColor(0xFF000000); Log.d("Info", "status is : " + status); if (status == 1) { holder.txtUser.setTextColor(0xFF005CE6); } else if (status == 2) { holder.txtUser.setTextColor(0xFFD67600); } else if (status == 3) { holder.txtUser.setTextColor(0xFF000000); } else if (status == 4) { holder.txtUser.setTextColor(0xFFDB0000); holder.txtText.setTextColor(0xFF660000); } else if (status == 5) { holder.txtUser.setTextColor(0xFF009933); holder.txtText.setTextColor(0xFF003300); } holder.txtText.setText(entry.text); holder.txtUser.setText(entry.user); holder.txtVersion.setText(entry.v); holder.txtZeit.setText(entry.time); return row; } static class ChatHolder { RelativeLayout background; TextView txtText; TextView txtUser; TextView txtVersion; TextView txtZeit; } @Override public int getCount() { return data.size(); } @Override public ChatListItem getItem(int arg0) { return data.get(arg0); } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return 0; } } </code></pre>
    singulars
    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.
 

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