-1

ListViewAndroidでビルドしたい。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);
4

2 に答える 2

0

要件に合わせてカスタム リスト アダプターを使用する必要があります。

ステップ1

ListView を初期化する

ステップ2

を使用してアダプタを呼び出します

MultiColumnAdapter review = new MultiColumnAdapter(this,logDetails_cursor);
listview.setAdapter(review);

ステップ 3

MultiColumnAdapter

 class MultiColumnAdapter extends CursorAdapter {
    LayoutInflater mInflater;
    SimpleDateFormat sdf;

    RequestLogAdapter(Context context, Cursor cursor) {
        super(context, cursor);
        mInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

         //Get your details here
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
                    //Create xml for multicolumnlistview
        return mInflater.inflate(R.layout.mulitcolumnlistview, parent, false);
    }

    @Override
    public void bindView(View row, Context context, Cursor cursor) {
                    //Rows of multicolumn listview
        TextView reqdate = (TextView) row
                .findViewById(R.id.firstcolumn);
        TextView reqtime = (TextView) row
                .findViewById(R.id.secondcolumn);
        TextView reqfromlocation = (TextView) row
                .findViewById(R.id.thirdcolumn);

        String text1 = cursor.getString(i_requestdate);
        reqdate.setText(yourtext);

        String text2 = cursor.getString(i_requesttime);
        reqtime.setText(timeRequested);

        String text3 = cursor.getString(i_requestfromlocation);
        reqfromlocation.setText(yourtext);

       }
     }

multicolumnlistview ListView Xml

ここで背景色を設定できます。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:paddingTop="4dip"
 android:paddingBottom="6dip"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:orientation="horizontal"
 android:descendantFocusability="blocksDescendants">

 <TextView android:id="@+id/column1"
     android:layout_width="70dip"
     android:layout_height="wrap_content"
     android:textColor="@color/White" 
     android:layout_marginLeft="5dip"
     android:layout_weight="1" 
     android:textSize="16sp" />

 <TextView android:id="@+id/column2"
     android:layout_width="60dip"
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:textSize="16sp" 
     android:textColor="@color/White"   
     android:maxLines="1" />  

 <TextView android:id="@+id/column3"
     android:layout_width="50dip"
     android:layout_height="wrap_content"  
     android:textSize="17sp"  
     android:textColor="@color/White"  
     android:layout_weight="2" /> 

それが役に立てば幸い

于 2012-08-24T13:07:30.033 に答える