2列列表视图中的2列列表视图

时间:2013-04-02 05:39:16

标签: android

我想在我的前2列listview的第2列中放入2列listview,但我不知道如何使用相同的代码使其成为3列列表视图?在第1列中的位置是一个图像,第二和第三列都是文本,我试过但它有错误...我的代码是这样的..

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;

public class WeatherToday extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_weathertoday);


    ListView view = (ListView) findViewById(R.id.todaylist);
    final List<MyStringPair> myStringPairList = MyStringPair.makeData(10);
    MyStringPairAdapter adapter = new MyStringPairAdapter(this, myStringPairList);

    view.setAdapter(adapter);
}
}

stringpairlist

import java.util.ArrayList;
import java.util.List;

public class MyStringPair {

private String columnOne;
private String columnTwo;

public MyStringPair(String columnOne, String columnTwo) {
    super();
    this.columnOne = columnOne;
    this.columnTwo = columnTwo;


}

public String getColumnOne() {
    return columnOne;
}
public void setColumnOne(String columnOne) {
    this.columnOne = columnOne;
}
public String getColumnTwo() {
    return columnTwo;
}
public void setColumnTwo(String columnTwo) {
    this.columnTwo = columnTwo;
}


public static List<MyStringPair> makeData(int n) {
    List<MyStringPair> pair = new ArrayList<MyStringPair>();

        pair.add(new MyStringPair("Weather Condition", "Partly Cloudy"));
        pair.add(new MyStringPair("Temperature", "30 Celcius "));
        pair.add(new MyStringPair("Moisture", "Dew Point:" ));
        pair.add(new MyStringPair("Wind", "Column2 "));
        pair.add(new MyStringPair("Precipitation", "Column2 "));
        pair.add(new MyStringPair("Condition", "Pressure:1014 mb "));


    return pair;
}

}

适配器

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyStringPairAdapter extends BaseAdapter {
private Activity activity;
private List<MyStringPair> stringPairList;


public MyStringPairAdapter(Activity activity, List<MyStringPair> stringPairList) {
    super();
    this.activity = activity;
    this.stringPairList = stringPairList;
}

@Override
public int getCount() {
    return stringPairList.size();
}

@Override
public Object getItem(int position) {
    return stringPairList.get(position);
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
        LayoutInflater inflater = activity.getLayoutInflater();
        convertView = inflater.inflate(R.layout.listrow, null);
    }

    TextView col1 = (TextView) convertView.findViewById(R.id.column1);
    TextView col2 = (TextView) convertView.findViewById(R.id.column2);
    col1.setText(stringPairList.get(position).getColumnOne());
    col2.setText(stringPairList.get(position).getColumnTwo());

    return convertView;
}
}

我在列上添加了一个框,我想要另外2列...基本上我想在较小的框中放两个列我想将文本分成两部分所以我需要两列但是我出于想法

enter image description here

0 个答案:

没有答案