getting 0 on listView.getChildCount()
I want to change the font and size of textlist that I created, but getting 0 on listView.getChildC开发者_开发问答ount()
.
I want to change the font of text before display them. Here is my code:
public class NewsActivity extends ListActivity {
public ReadXMLFile ReadXML;
public ArrayList<String> ynetList =new ArrayList<String>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,ynetList));
View v=getListView() ;
ListView lv = this.getListView();
//select red color borders*/
int[] colors = {0, 0xFFFF0000, 0}; // red for the example
lv.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
lv.setDividerHeight(1);
lv.setTextFilterEnabled(true);
//test
int childCount = lv.getChildCount();
for (int i = 0; i < childCount; i++)
{
View vf = lv.getChildAt(i);
TextView tx = (TextView) vf.findViewById(R.id.textView);
tx.setTextSize(25);
tx.setTextColor(Color.RED);
}
You can extend ArrayAdapter and Override getView() method like that:
View view = super.getView();
TextView tx = (TextView) view .findViewById(R.id.textView);
tx.setTextSize(25);
tx.setTextColor(Color.RED);
return view;
You can create custom layout - items_news -
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="75sp"
android:text="Text" />
and use in the same adapter.
精彩评论