1

リソースに表示したい配列がありますが、ListView惨めに失敗しているので、誰かが私が間違っていることと、これを達成するために何をすべきかを教えてくれるかもしれません。これが私が使用しているコードです:

私のXMLリソース:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">myApp</string>
<string-array name="EstadosArray">
    <item >Estado1</item>
    <item >Estado2</item>
    <item >Estado3</item>
    <item >Estado4</item>
    <item >Estado5</item>
    <item >Estado6</item>        
</string-array>
</resources>

私の活動では:

public class myMain extends Activity{
String[] Estados;
eAdapter ea=null;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

    Estados = getResources().getStringArray(R.array.EstadosArray);
    ea = new eAdapter();
    ListView EstadosList = (ListView) findViewById(R.id.estadosList);
    EstadosList.setAdapter(ea);

}

class eAdapter extends ArrayAdapter<String> {
    eAdapter() {
            super(myMain.this, android.R.layout.simple_list_item_1, Estados);
            }
    public View getView(int position, View convertView, ViewGroup parent) {
        eHolder holder;
        if (convertView == null) {
            LayoutInflater inflater = getLayoutInflater();
            convertView = inflater.inflate(R.layout.esatdoitem, null);
            holder = new eHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (eHolder) convertView.getTag();
        }
        holder.populateFrom(Estados.get(position));  // HERE IS WHERE I HAVE THE issue is, I DON'T KNOW HOW TO GET THE POSITION, IS GIVING ME AN ERROR (CANNOT INVOKE GET(INT) ON THE ARRAY TYPE STRING[])
        return (convertView);
    }

}
class eHolder{
    public TextView esname=null;
    eHolder(View row) {
        esname = (TextView) row.findViewById(R.id.ename);
    }
    void populateFrom(String est) {
        esname.setText(est);
    }
}

string []がintではないことが問題の原因であることはわかっていますが、どうすれば修正できますか?それが私のリストのすべての行を埋める方法です。

編集:LogCat追加:

05-03 17:09:46.290: E/AndroidRuntime(271):  at com.zvzej.jlgproapps.mexicoguia.myMain$eHolder.populateFrom(myMain.java:468)
05-03 17:09:46.290: E/AndroidRuntime(271):  at com.zvzej.jlgproapps.mexicoguia.myMain$eAdapter.getView(myMain.java:456)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.widget.AbsListView.obtainView(AbsListView.java:1315)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.widget.ListView.onMeasure(ListView.java:1109)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.view.View.measure(View.java:8171)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.widget.RelativeLayout.measureChild(RelativeLayout.java:563)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:378)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.view.View.measure(View.java:8171)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.view.View.measure(View.java:8171)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.view.View.measure(View.java:8171)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.view.View.measure(View.java:8171)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.view.View.measure(View.java:8171)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.os.Looper.loop(Looper.java:123)
05-03 17:09:46.290: E/AndroidRuntime(271):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-03 17:09:46.290: E/AndroidRuntime(271):  at java.lang.reflect.Method.invokeNative(Native Method)
05-03 17:09:46.290: E/AndroidRuntime(271):  at java.lang.reflect.Method.invoke(Method.java:521)
05-03 17:09:46.290: E/AndroidRuntime(271):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 17:09:46.290: E/AndroidRuntime(271):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 17:09:46.290: E/AndroidRuntime(271):  at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1

1

やってみました:

holder.populateFrom(Estados[position]);

添加

これは:

    esname = (TextView) row.findViewById(R.id.ename);

察するに:

    esname = (TextView) row.findViewById(R.id.esname);
于 2012-05-03T23:55:09.087 に答える