gpt4 book ai didi

java - android中通过soap调用的 ListView

转载 作者:行者123 更新时间:2023-12-01 15:09:47 25 4
gpt4 key购买 nike

嗨,我已经成功开发了一个 ListView 应用程序..现在我必须单击该列表中的任何项目意味着详细描​​述将显示在下一个 Activity 中...它也成功完成..现在我的输出格式如下:

1   F   Krishna
2 Q Danesh
3 P Mercy

这里我必须点击2 Q Danesh项目,它会转到下一个 Activity 。必须显示下一个 Activity

Q Danesh

已成功运行。

但现在我希望需要像这样的格式的 ListView :

1 Krishna
2 Danesh
3 Mercy

在这里我必须点击2 Danesh表示它要转到下一个 Activity 并且下一个 Activity 必须显示

我该怎么办......请帮助我......

下面的代码是我的网络服务代码:

 public class RetailerWs {
public String customerData1(){
String customerInfo = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");

//查找客户ID最大的客户信息 ReadyStatement 语句 = con.prepareStatement("SELECT * FROM xcart_orders"); ResultSet 结果 = statements.executeQuery();

 while(result.next()){
customerInfo = customerInfo
+ result.getString("orderid")
+ " " // this to separate order id from status
+ result.getString("status")
+ " "
// this to separate order id from status
+ result.getString("login")
+ "&" ;
//Here "&"s are added to the return string. This is help to split the string in Android application
}
}

catch(Exception exc){
System.out.println(exc.getMessage());
}

return customerInfo;
}

}

这是我的 Android 代码:

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";
private static final String KEY_LOGIN = "login";


/** 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 = 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);



}
});
}


catch (Exception e) {
e.printStackTrace();
}
}

}

这是我的下一个 Activity :

 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 StrStatus = in.getStringExtra(KEY_STATUS);


// Displaying all values on the screen
TextView lblName = (TextView) findViewById(R.id.status_label);
lblName.setText(StrStatus);

}
}

请帮助我......

最佳答案

这是可能的。您可以将 Q 从列表屏幕转移到其他 Activity 。

您只需更改您的第一个 Activty(即您的 Q 值)

in.putExtra("StrStatus", StrStatus);

然后您可以通过以下方式在其他 Activity 中获取此信息

Bundle extras=getIntent().getExtras();
if(extras!=null) {
STRStatus=extras.getString("StrStatus");
}

这将有你的Q值,你可以做任何你想做的事。

-----
顺便说一句 - 你遇到了什么错误?您可以使用它来单击您的列表项

public void onListItemClick(ListView parent,View v,int position,long id){
try {
TextView t4=(TextView)v.findViewById(R.id.No);

if (t4!=null){
BeanClass/*ClassName*/ mSelected;
int idx=position;
mSelected=m_adapter.getItem(idx);
String ActionID=mSelected.getID();

Intent intent=new Intent(this,SoneActivity.class);
intent.putExtra("StrStatus", StrStatus);
startActivity(intent);
}
}

关于java - android中通过soap调用的 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12489518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com