我已经开发了android listview通过soap调用成功..现在我必须点击该列表中的任何项目意味着显示详细说明...
这是我的示例列表视图格式:
1 F
2 Q
3 P
这里我需要点击1 F项表示F显示在下一个activity.samething我必须点击2 Q表示Q显示在下一个活动。
下一个活动必须像这样:(点击1 F表示它转到下一个活动并显示F)
F
我怎样才能发展这一点。请帮助我...
在这里,我必须点击1 F表示它将转到下一个活动...下一个活动不会显示任何内容。
这是我的代码:
public class RetailerActivity extends Activity {
ListView list;
private static final String SOAP_ACTION = "http://xcart.com/customerData1";
private static final String METHOD_NAME = "customerData1";
private static final String NAMESPACE = "http://xcart.com";
private static final String URL = "http://192.168.1.168:8089/XcartLogin/services/RetailerWs?wsdl";
private static final String KEY_STATUS = "status";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
SoapPrimitive s = response;
String str = s.toString();
String resultArr[] = str.split("&");
list=(ListView)findViewById(R.id.list);
list.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1,resultArr));
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String status = ((TextView) view.findViewById(R.id.status)).getText().toString();
Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra(KEY_STATUS, status);
startActivity(in);
}
});
}
catch (Exception e) {
e.printStackTrace();
}
}
}
这是另一项活动:
public class SingleMenuItemActivity extends Activity {
// XML node keys
static final String KEY_STATUS = "status";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_list_item);
Intent in = getIntent();
String status = in.getStringExtra(KEY_STATUS);
// Displaying all values on the screen
TextView lblName = (TextView) findViewById(R.id.status_label);
lblName.setText(status);
}
}
这是single_list_item.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Name Label -->
<TextView android:id="@+id/status_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="25dip"
android:textStyle="bold"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:textColor="#dc6800"
/>
</LinearLayout>
请帮助我..我可以开发这个。
答案 0 :(得分:2)
这里我认为onItem点击你没有获得价值所以得到像
这样的值list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String status = parent.getItemAtPosition(position).toString();
String[] status1 = status.split(" ");
String StrStatus = status1[1].toString();
Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra(KEY_STATUS, StrStatus );
startActivity(in);
}
});
有关将ActivityA传递给B并获取值的更多值,请参阅here这可能会对您有所帮助