android Listenansicht getItemAtPosition() kehrt zurück, raw-Daten

implementierte ich eine Liste anzeigen seine Arbeit gut, aber wenn ich auf der Liste, es gibt mir die raw-Daten, die getItemAtPosition(position) gibt mir.

folgende code ist der code, dass ich mit

public class FirstTab extends Activity{

    private TabHostProvider tabProvider;
    private TabView tabView;
    private static String[] country1;
    private ListView speakerList;
    final Handler mHandler = new Handler();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Context context = getApplicationContext();
        tabProvider = new TabbarView(this);
        tabView = tabProvider.getTabHost("main");
        tabView.setCurrentView(R.layout.firsttab);
        setContentView(tabView.render(0));
        String temp[] = new String[]{"furqan","furqan1","furqan2"};
        Weather weather_data[] = new Weather[temp.length];
        for(int i = 0;i<temp.length;i++)
        {
            weather_data[i] = new Weather(R.drawable.ic_launcher, temp[i]);
        }

        WeatherAdapter adapter = new WeatherAdapter(this,R.layout.listview_item_row, weather_data);
        speakerList = (ListView)findViewById(R.id.speakerList);
        View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
        speakerList.addHeaderView(header);
        speakerList.setAdapter(adapter);

        final ViewFlipper viewflipper = (ViewFlipper) findViewById(R.id.viewflipper);
        speakerList.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(final AdapterView<?> arg0, View arg1, final int arg2,long arg3) {
                //TODO Auto-generated method stub


                String item = speakerList.getItemAtPosition(arg2).toString();
                Log.d("the  value is", item);
                        /*View item = (View) (speakerList.getItemAtPosition(arg2));
                        String item = arg0.getItemAtPosition(arg2).toString();
                        Log.d("the  value is", item);*/
                        //Toast.makeText(getApplicationContext(), arg2, 1).show();



            }

        });

    }   
}

Oben ist die Haupttätigkeit.Im folgenden ist der adapter

public class weatheradapter {



    public static class WeatherAdapter extends ArrayAdapter<Weather>{

        Context context; 
        int layoutResourceId;    
        Weather data[] = null;

        public WeatherAdapter(Context context, int layoutResourceId, Weather[] data) {
            super(context, layoutResourceId, data);
            this.layoutResourceId = layoutResourceId;
            this.context = context;
            this.data = data;
        }

        static class WeatherHolder
        {
            ImageView imgIcon;
            TextView txtTitle;
        }



        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            WeatherHolder holder = null;

            if(row == null)
            {
                LayoutInflater inflater = ((Activity)context).getLayoutInflater();
                row = inflater.inflate(layoutResourceId, parent, false);

                holder = new WeatherHolder();
                holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
                holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);

                row.setTag(holder);
            }
            else
            {
                holder = (WeatherHolder)row.getTag();
            }

            Weather weather = data[position];
            holder.txtTitle.setText(weather.title);
            holder.imgIcon.setImageResource(weather.icon);

            return row;
        }


    }
}

dies ist die xml-Datei

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center" android:gravity="center" android:background="#00FFcc">

    <ViewFlipper android:id="@+id/viewflipper" android:layout_width="fill_parent" android:layout_height="fill_parent" > 

        <ListView android:id="@+id/speakerList" android:layout_width="fill_parent" android:layout_height="fill_parent" />

        <ListView android:id="@+id/categoryList" android:layout_width="fill_parent" android:layout_height="wrap_content" />


    </ViewFlipper>

</LinearLayout>

Folgenden wird das layout für die Ansicht der Liste

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp">

     <ImageView android:id="@+id/imgIcon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:gravity="center_vertical"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="15dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp" />



       <TextView android:id="@+id/txtTitle"
         android:text="@+id/txtTitle"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_vertical"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:textStyle="bold"
        android:textSize="22dp"
        android:textColor="#000000"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp" />

</LinearLayout>

brauchen Hilfe vielen Dank

InformationsquelleAutor Furqan Ahmed | 2012-04-01

Schreibe einen Kommentar