melvintcs
melvintcs

Reputation: 551

get the string from array

i wanted to returned the selected value from the listview, i can do it if i using the default listview, but now i customize the listview, got imageview, ratingbarm and few textview. how can i return the value of title at the toast after user has selected? below is my code:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.appslist);

        list=(ListView)findViewById(R.id.lvApps);        


        SoapObject Request = new SoapObject (NAMESPACE, METHOD_NAME);
    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(Request);

        AndroidHttpTransport aht = new AndroidHttpTransport(URL);

        try
        {
            aht.call(SOAP_ACTION, soapEnvelope);
            SoapObject resultString = (SoapObject) soapEnvelope.getResponse();          

            String[] strTitle = new String[resultString.getPropertyCount()];
            String[] strDeveloper = new String[resultString.getPropertyCount()];
            String[] strRating = new String[resultString.getPropertyCount()];
            String[] strLogo = new String[resultString.getPropertyCount()];         

            for(int i =0; i<resultString.getPropertyCount(); i++)
            {
                SoapObject array = (SoapObject) resultString .getProperty(i);
                strTitle[i] = array.getProperty(1).toString();  //get title  
                strDeveloper[i] = array.getProperty(3).toString(); //get developer
                strRating[i] = array.getProperty(4).toString(); //get rating
                strLogo[i] = array.getProperty(5).toString();   //get photo             
            }
            adapter=new AppsListAdapter(this, strTitle, strDeveloper, strRating, strLogo);
            list.setAdapter(adapter);

            list.setOnItemClickListener(new OnItemClickListener(){
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    Object GetLabel = list.getItemAtPosition(arg2);
                          //Toast here
                    Toast.makeText(getApplicationContext(), GetLabel.toString(), Toast.LENGTH_SHORT).show();                        

            });
        }

        catch(Exception e)
        {

        }
    }
}

Upvotes: 1

Views: 206

Answers (2)

Aalok Sharma
Aalok Sharma

Reputation: 1025

Try this

lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View v, int position,
                    long arg3) {
                // TODO Auto-generated method stub
                HashMap<String, String> o = (HashMap<String, String>) mylist
                        .get(position);
                Log.v("o", o + "n");
                String d = o.get("the string value you want to retrieve");
                Log.v("Tapped ", d);

            }
        });

where "lv" is your listview and mylist is your arraylist

Upvotes: 1

Dheeresh Singh
Dheeresh Singh

Reputation: 15701

You should create model (bean) of all the data in one item means wrap the data in objects and create the array of that models and send that array to adapter..........

But for now there a few ways to acive you task :

1- you have the position of selected item which can be used as index in the strTitle to get the particular title.

String title = strTitle[position]; /// if think can Put the null and length check if to make it safe

2- you have the view of the list in callback public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) from that view using findViewbyid you can get your textview having title

String s =(String) ((TextView) view.findViewById(R.id.title)).getText(); //view is selected row view

or

TextView txt =(TextView)arg0.getChildAt(position-lv.firstVisiblePosition()).findViewById(R.id.mylistviewtextview); //arg0 is parent view String keyword = txt.getText().toString();

3-

Upvotes: 1

Related Questions