1

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

主要的

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);
}
}

字符串对列表

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 列的列上添加了一个框..基本上我想在较小的框中再放两列我想将文本分成两部分,所以我需要两列但我没有想法

在此处输入图像描述

4

0 回答 0