Android ListView ActionListener
我正在开发一个体育应用程序,在那里可以找到关于每日比赛更新的信息。 我需要有一个列表视图,以日期作为标题,并预览该日期事件。单击列表上的此特定日期,将显示当天事件的完整详细信息。 当前,当我单击列表中的某个日期时,会显示详细信息…但对于数据库中的所有日期:但我需要显示一天的详细信息。 这是密码Android ListView ActionListener,android,listview,actionlistener,Android,Listview,Actionlistener,我正在开发一个体育应用程序,在那里可以找到关于每日比赛更新的信息。 我需要有一个列表视图,以日期作为标题,并预览该日期事件。单击列表上的此特定日期,将显示当天事件的完整详细信息。 当前,当我单击列表中的某个日期时,会显示详细信息…但对于数据库中的所有日期:但我需要显示一天的详细信息。 这是密码 private class displaymatches extends AsyncTask<Void, Void, Void> { @Override protected
private class displaymatches extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(Void... arg0) {
HttpHandler sh = new HttpHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(JSON_URL);
Log.e(TAG, "Response from url: " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
JSONArray listavai = jsonObj.getJSONArray("result");
// looping through All matches
for (int i = 0; i < listavai.length(); i++) {
JSONObject c = listavai.getJSONObject(i);
dateofmatch = c.getString("dateofmatch");
String league = c.getString("gameleague");
String teams = c.getString("matches");
String gametime = c.getString("gametime");
String tip = c.getString("gametip");
String odds=c.getString("odds");
HashMap<String, String> games = new HashMap<>();
HashMap<String, String> gamesdetail = new HashMap<>();
// adding each child node to HashMap key => value
games.put("dateofmatch", dateofmatch);
games.put("gameleague", league);
games.put("matches", teams);
//detailing
gamesdetail.put("gameleague",league);
gamesdetail.put("matches",teams);
gamesdetail.put("gametime",gametime);
gamesdetail.put("gametip",tip);
gamesdetail.put("odds",odds);
// adding contact to contact list
matcheslist.add(games);
detailmatchlist.add(gamesdetail);
}
} catch (final JSONException e) {
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Json parsing error: " + e.getMessage(),
Toast.LENGTH_LONG)
.show();
}
});
}
} else {
Log.e(TAG, "Couldn't get json from server.");
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Couldn't get json from server. Check LogCat for possible errors!",
Toast.LENGTH_LONG)
.show();
}
});
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
/**
* Updating parsed JSON data into ListView
* */
swipeContainer.setRefreshing(false);
ListAdapter adapter = new SimpleAdapter(
MainActivity.this, matcheslist,
R.layout.list_item, new String[]{"dateofmatch", "gameleague",
"matches"}, new int[]{R.id.name,
R.id.email, R.id.mobile});
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// dateofmatch = ((TextView)view).getText().toString();
// dateofmatch
final ListAdapter detail = new SimpleAdapter(
MainActivity.this, detailmatchlist,
R.layout.detail_list_item, new String[]{"gameleague", "matches",
"gametime", "gametip", "odds"}, new int[]{R.id.league,
R.id.matches, R.id.gametime, R.id.gametip, R.id.odds});
lv.setAdapter(detail);
}
});
}
}
<?php
define('HOST','localhost');
define('USER','root');
define('PASS','root');
define('DB','Bets');
$con = mysqli_connect(HOST,USER,PASS,DB);
$sql = "select * from oddsdata";
$res = mysqli_query($con,$sql);
$result = array();
while($row = mysqli_fetch_array($res)){
array_push($result,
array('dateofmatch'=>$row[0],
'gameleague'=>$row[1],
'matches'=>$row[3],
'gametime'=>$row[4],
'gametip'=>$row[5],
'odds'=>$row[6]
));
}
echo json_encode(array("result"=>$result));
mysqli_close($con);
?>
private类显示任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
//显示进度对话框
pDialog=新建进度对话框(MainActivity.this);
setMessage(“请稍候…”);
pDialog.setCancelable(假);
pDialog.show();
}
@凌驾
受保护的Void doInBackground(Void…arg0){
HttpHandler sh=新的HttpHandler();
//向url发出请求并获得响应
字符串jsonStr=sh.makeServiceCall(JSON_URL);
Log.e(标签,“来自url的响应:+jsonStr”);
if(jsonStr!=null){
试一试{
JSONObject jsonObj=新的JSONObject(jsonStr);
//获取JSON数组节点
JSONArray listavai=jsonObj.getJSONArray(“结果”);
//在所有比赛中循环
对于(int i=0;ivalue
比赛。推杆(“比赛日期”,比赛日期);
游戏。推杆(“游戏联盟”,联盟);
比赛。推杆(“比赛”,团队);
//详细说明
gamesdetail.put(“游戏联盟”,联盟);
gamesdetail.put(“比赛”,团队);
gamesdetail.put(“gametime”,gametime);
gamesdetail.put(“gamestip”,tip);
gamesdetail.put(“赔率”,赔率);
//将联系人添加到联系人列表
matcheslist.add(游戏);
detailmatchlist.add(gamesdetail);
}
}捕获(最终JSONException e){
Log.e(标记“Json解析错误:”+e.getMessage());
runOnUiThread(新的Runnable(){
@凌驾
公开募捐{
Toast.makeText(getApplicationContext(),
Json分析错误:“+e.getMessage(),
吐司长度(长)
.show();
}
});
}
}否则{
e(标记“无法从服务器获取json”);
runOnUiThread(新的Runnable(){
@凌驾
公开募捐{
Toast.makeText(getApplicationContext(),
“无法从服务器获取json。请检查LogCat以了解可能的错误!”,
吐司长度(长)
.show();
}
});
}
返回null;
}
@凌驾
受保护的void onPostExecute(void结果){
super.onPostExecute(结果);
//关闭进度对话框
if(pDialog.isShowing())
pDialog.disclose();
/**
*将解析的JSON数据更新到ListView中
* */
swipContainer.setRefreshing(false);
ListAdapter=新的SimpleAdapter(
MainActivity.this、matcheslist、,
R.layout.list_项,新字符串[]{“dateofmatch”,“GameAgue”,
“matches”},新int[]{R.id.name,
R.id.email,R.id.mobile});
低压设置适配器(适配器);
lv.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父视图、视图、整型位置、,
长id){
//dateofmatch=((TextView)视图).getText().toString();
//匹配日期
最终列表适配器详细信息=新SimpleAdapter(
MainActivity.this、detailmatchlist、,
R.layout.detail_list_项,新字符串[]{“游戏联盟”,“比赛”,
“游戏时间”,“游戏提示”,“赔率”},新的整数[]{R.id.league,
R.id.matches,R.id.gametime,R.id.gametip,R.id.赔率});
低压设置适配器(详图);
}
});
}
}
我不清楚您的问题,请出示您的json。匹配日期并使用for循环获取特定的JSON对象@Arpittatel,看看你能不能帮忙