When i populate an ArrayAdapter, at first the rows in the visible part of the screen will be blank except the first row, which will be an undesired result. Then when I scroll it down and then come back all the screen will be set correctly...please some one tell me why this behavior happens ?
Code :
homeListView = (ListView) findViewById(R.id.home_list);
homeArrayAdapter = new HomeListArrayAdapter(this, R.id.home_list,
homeList);
homeListView.setAdapter(homeArrayAdapter);
Next Part as Class extending ArrayAdapter, an Inner Class to Activity:
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.home, null);
}
Home item = (homeList).get(position);
if (item != null) {
if (item.type_text == Home.SIMPLE_SHOUT) {
TextView tv1 = (TextView) findViewById(R.id.hTextView01);
if (tv1 != null) {
tv1
.setText(String.format(" %s\t:",
item.friend_name));
final String item_friend_id_01 = String
.valueOf(item.users_id);
tv1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast toast = Toast.makeText(Tranz.this,
item_friend_id_01, Toast.LENGTH_LONG);
toast.show();
}
});
}
TextView tv2 = (TextView) findViewById(R.id.hTextView02);
if (tv2 != null) {
tv2.setText(String.format("\t%s", item.message));
tv2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
TextView tv3 = (TextView) findViewById(R.id.hTextView03);
if (tv3 != null) {
tv3.setVisibility(0);
tv3.setText(null);
tv3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
ImageView imageView = (ImageView) findViewById(R.id.file_image);
if (imageView != null) {
imageView.setBackgroundDrawable(null);
}
} else if (item.type_text == Home.FILE_SHOUT) {
TextView tv1 = (TextView) findViewById(R.id.hTextView01);
The code is getting truncated, so the whole code is not appearing here. I'm sorry about that. Here what i have tried is to put the values in the object of class Home into two textViews and an ImageView, which may vary upon the value returned by variable item.type_text
Also if somebody can tell me another best practice to do this, please help.