我想ListView
在Android中构建一个。它应该有multiple coloums
并且有可能change color of only some rows
。我已经尝试过了,但我认为它调用了 LinearLayout 的toString()。我不明白text inside the TextView
。这几天我都试过了。请帮忙。下面的代码只是真实项目的实验。
public class EventActivity extends ListActivity {
List<Event> events2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.event_layout);
ListView listView = (ListView) findViewById(R.id.listEvents);
listView = getListView();
TextView t1 = new TextView(getBaseContext());
TextView t2 = new TextView(getBaseContext());
TextView t3 = new TextView(getBaseContext());
TextView t4 = new TextView(getBaseContext());
TextView t5 = new TextView(getBaseContext());
TextView t6 = new TextView(getBaseContext());
TextView t7 = new TextView(getBaseContext());
t1.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
t2.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
t3.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
t4.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
t5.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
t6.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
t1.setText("1111");
t2.setText("2111");
t3.setText("3111");
t4.setText("4111");
t5.setText("5111");
t6.setText("6111");
t7.setText("7111");
t1.setBackgroundColor(Color.GREEN);
t4.setBackgroundColor(Color.GREEN);
LinearLayout ll = new LinearLayout(this);
ll.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(t1);
ll.addView(t2);
ll.addView(t3);
ll.addView(t4);
ll.addView(t5);
ll.addView(t6);
ll.addView(t7);
ArrayList<LinearLayout> lllist = new ArrayList<LinearLayout>();
lllist.add(ll);
ArrayAdapter<LinearLayout> eventAdapter = new ArrayAdapter<LinearLayout>(EventActivity.this,
android.R.layout.simple_list_item_1,lllist );
listView.setAdapter(eventAdapter);