我在1个活动中动态加载按钮,然后加载按钮的onClick()事件。在下面的活动中,我想显示与按钮相关的详细信息,例如,如果用户单击QUEST,它应仅显示QUEST详细信息,如果用户单击SRL,则应仅显示SRL详细信息。我无法得到。有人可以帮忙吗?
public void loadDescriptionList() {
String url = "https://diagnostic.hisaabwaale.in/AndroidAppController/testGet";
final ProgressDialog progressDialog = new ProgressDialog(TestDetails.this);
progressDialog.setMessage("Loading Data...");
progressDialog.show();
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressDialog.dismiss();
try {
obj = new JSONObject(response);
heroArray = obj.getJSONArray("list");
for (int i = 0; i < heroArray.length(); i++) {
heroObject = heroArray.getJSONObject(i);
TDescription hero = new TDescription(heroObject.getString("test_code"), heroObject.getString("test_description"), heroObject.getString("test_price"));
heroList.add(hero);
}
adapter = new ListViewAdapter(heroList, getApplicationContext());
listView.setAdapter(adapter);
} catch (JSONException e) {
progressDialog.dismiss();
e.printStackTrace();
Toast.makeText(getApplicationContext(), "No Records Found", Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), "No Records Found", Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("franchise", franchise);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
后端api
function testGet(){
$response = array();
$franchise = $this->input->post('franchise');
$result = $this->testModel->testlist($franchise);
if($result != 0){
$response['status'] = 200;
$response['list'] = $result;
}else{
$response['status'] = 201;
$response['msg'] = 'No Records';
}
echo json_encode($response);
}
这是模型
public function testlist($franchise)
{
$query = "SELECT t.id, t.franchise_id, t.test_code, t.test_description, t.test_price
FROM `".$this->table."` as t
WHERE t.franchise_id = ".$franchise;
$result = $this->db->query($query);
if($result->num_rows() > 0){
return $result->result();
}else{
return 0;
}
}
logcat的
12-22 00:24:34.459 22632-22632/hisaabwaale.in.hisaabwaale E/MultiWindowProxy: getServiceInstance failed!
12-22 00:24:37.574 22632-22632 /? E / MultiWindowProxy:getServiceInstance失败了! 12-22 00:24:37.696 22632-22632 /? E / MultiWindowProxy:getServiceInstance失败了! 12-22 00:24:38.637 22632-22863 /? E / NativeCrypto:ssl = 0xacc22880 cert_verify_callback x509_store_ctx = 0x9f0f9e4c arg = 0x0 12-22 00:24:38.637 22632-22863 /? E / NativeCrypto:ssl = 0xacc22880 cert_verify_callback调用verifyCertificateChain authMethod = ECDHE_RSA 12-22 00:24:40.080 22632-22664 /? E / Surface:getSlotFromBufferLocked:未知缓冲区:0xa0921dc0 12-22 00:24:40.111 22632-22632 /? E /错误:Failedorg.json.JSONException:索引2超出范围[0..2) 12-22 00:24:40.255 22632-22664 /? E / Surface:getSlotFromBufferLocked:未知缓冲区:0xa0921640 12-22 00:24:55.343 22632-22632 /? E / MultiWindowProxy:getServiceInstance失败了! 12-22 00:24:55.452 22632-23164 /? E / Volley:[125517] NetworkDispatcher.run:未处理的异常java.lang.NullPointerException:尝试调用虚方法&#39; int java.lang.String.length()&#39;在null对象引用上 java.lang.NullPointerException:尝试调用虚方法&#39; int java.lang.String.length()&#39;在null对象引用上 在libcore.net.UriCodec.encode(UriCodec.java:132) 在java.net.URLEncoder.encode(URLEncoder.java:57) 在com.android.volley.Request.encodeParameters(Request.java:484) 在com.android.volley.Request.getBody(Request.java:470) 在com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:253) 在com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:227) 在com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:107) 在com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:97) 在com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114) 12-22 00:24:55.742 22632-22664 /? E / Surface:getSlotFromBufferLocked:未知缓冲区:0xa0921aa0
答案 0 :(得分:0)
Button QUEST= (Button) findViewById(R.id.QUEST);
QUEST.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString('franchise', '8');
}
});
Button SRL= (Button) findViewById(R.id.SRL);
SRL.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Same as other, just different franchise
}
});
当您打开下一个活动时:
String franchise = getIntent().getExtras().getString(franchise)
然后调用loadDescriptionList()
也许它需要一个字符串?像
loadDescriptionList(String franchise)
当您打开新活动时:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadDescriptionList(getIntent().getExtras().getString(franchise))
}
我假设loadDescriptionList()
正在调用下一个活动。希望这有助于或引导您朝着正确的方向前进。
修改强>
您也可以使用下面的Bundle
将值传递给下一个活动:
Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.putString(key, value);
mIntent.putExtras(mBundle);