Java 在android中使用类将数据绑定到listview

Java 在android中使用类将数据绑定到listview,java,android,eclipse,android-intent,android-emulator,Java,Android,Eclipse,Android Intent,Android Emulator,嘿,每个人,我想显示列表视图android ackage com.example.ewa import java.util.ArrayList; import java.util.Arrays; import android.os.Bundle; import android.app.Activity; import android.app.TabActivity; import android.content.Intent; import android.view.Menu; import

嘿,每个人,我想显示列表视图android

ackage com.example.ewa

import java.util.ArrayList;
import java.util.Arrays;

import android.os.Bundle;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        ListView lst = (ListView) findViewById(R.id.listView1);
        tesst obj = new tesst();
        tesst[] ooo = new tesst[100];
        for(int i=0;i<ooo.length-1;i++)
        {
            ooo[i]= new tesst();
        }
        ooo[0].abss="Mercury";
        ooo[1].abss="Venus";
        String[] ppp= new String[1];
        for(int i=0;i<=1;i++)
        {
            ppp[i]=(String)ooo[i].abss;
        }
        String[] planets = new String[] { "Mercury", "Venus", "Earth", "Mars",
                "Jupiter", "Saturn", "Uranus", "Neptune" };
        //ArrayList<String> planetList = new ArrayList<String>();
        //planetList.addAll(Arrays.asList(ppp));

        ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this,
                R.layout.simplerow, R.id.textView1, ppp);

        listAdapter.add(ppp[0]);
        listAdapter.add(ppp[1]);

        // Add more planets. If you passed a String[] instead of a List<String>
        // into the ArrayAdapter constructor, you must not add more items.
        // Otherwise an exception will occur.


        // Set the ArrayAdapter as the ListView's adapter.
        lst.setAdapter(listAdapter);

如何修复请帮助我你读了这些行吗

// Add more planets. If you passed a String[] instead of a List<String>
// into the ArrayAdapter constructor, you must not add more items.
// Otherwise an exception will occur.
无需显式添加这些项

String[]ppp=。。。
String[] ppp = ...
List<string> list = new List<string>(ppp);

listAdapter.add(list.get(0));
listAdapter.add(list.get(1));
列表=新列表(ppp); 添加(list.get(0)); add(list.get(1));

这就是你想要的吗?

嗨,我找到了问题所在。您的are数组声明错误

更改此行:

String[] ppp= new String[2];
原因,在你的代码中

 String[] ppp= new String[1];
    for(int i=0;i<=1;i++)
    {
        ppp[i]=(String)ooo[i].abss;
    }
String[]ppp=新字符串[1];

对于(int i=0;iprakash我的朋友,如果我删除这一行,那么对输出没有影响更改字符串[]ppp=新字符串[1];更改字符串[]ppp=新字符串[2];检查我的另一个答案否我有类tesst和类有成员abss..使用类作为数组并为类的数组赋值,但问题是我想将类数组转换为字符串数组,字符串数组用于绑定ListView请将此标记为答案,然后其他人将使用此。谢谢
String[] ppp= new String[2];
 String[] ppp= new String[1];
    for(int i=0;i<=1;i++)
    {
        ppp[i]=(String)ooo[i].abss;
    }