我想从列表视图中返回选定的值,如果我使用默认列表视图,我可以做到,但现在我自定义列表视图,获得了图像视图、评分栏和一些文本视图。用户选择后如何在 toast 中返回 title 的值?下面是我的代码:
@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)
{
}
}
}