2

我正在创建一个 android 应用程序,我想在列表视图中显示微调器和 textview。我为微调器和 textview 的值使用了单独的 xml 类。对于以下代码示例,它仅显示来自 textview 的值而不是来自微调器的值。 .如何显示微调器和 textview 的值..i;对于 android 编程来说是全新的..

package com.example.dcsd;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class Result extends ListActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.result);
    setListAdapter(new MyAdapter(this,android.R.layout.simple_list_item_1,R.id.textView1, getResources().getStringArray(R.array.modules)));
    setListAdapter(new MyAdapter(this, android.R.layout.simple_spinner_dropdown_item,R.id.spinner1, getResources().getStringArray(R.array.grades)));

}
private class MyAdapter extends ArrayAdapter<String>{

    public MyAdapter(Context context, int resource, int textViewResourceId,
            String[] strings) {
        super(context, resource, textViewResourceId, strings);
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row=inflater.inflate(R.layout.item_layout, parent,false);
        String[] items=getResources().getStringArray(R.array.modules);
        TextView tv=(TextView) row.findViewById(R.id.textView1);        
        tv.setText(items[position]);
        Log.d("num", "lu");
        return row; 
    }
    @Override
    public View getDropDownView(int position, View convertView,
            ViewGroup parent) {
        LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row=inflater.inflate(R.layout.item_layout, parent,false);      
        String[] items=getResources().getStringArray(R.array.grades);
        Spinner sp = (Spinner) findViewById(R.id.spinner1);
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(Result.this, android.R.layout.simple_spinner_item,items);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp.setAdapter(adapter);
        Log.d("num", "huuuu");      
        return row;
    }
}
}
4

0 回答 0