- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
xml文件第一个文件是设计的 xml 文件。
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listviewtask"/>
</LinearLayout>
</RelativeLayout>
rawtask.xml 文件这是原始文件,这里是 ListView 的设计
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="@drawable/property_display_box"
android:id="@+id/listview1ll">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Task Name"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textSize="30dp"
android:id="@+id/lvtaskname" />
<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textSize="30dp"
android:hint="Task Details"
android:layout_gravity="center"
android:id="@+id/lvtaskdetails"
/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Details"
android:layout_marginLeft="40dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textSize="30dp"
android:id="@+id/lvchkbox"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:id="@+id/lvl1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Remaining Time:"
android:textSize="20dp"
android:id="@+id/lvrt"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Done"
android:layout_marginLeft="90dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:id="@+id/lvdone"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Listviewadapter.java显示 listviewadapter.java
public class ListViewAdapter2 extends BaseAdapter {
Context cntx;
AlertDialog.Builder alertDialogBuilder;
//int loader = R.drawable.ic_menu_gallery;
ArrayList<String> t_id=new ArrayList<String>();
ArrayList<String> t_tname=new ArrayList<String>();
ArrayList<String> t_detail=new ArrayList<String>();
// ArrayList<Float> itemRating=new ArrayList<Float>();
LayoutInflater inflater;
ArrayList<HashMap<String, String>> data;
//ImageLoader imageLoader;
HashMap<String, String> resultp = new HashMap<String, String>();
/*
* public ListViewAdapter(Context context, ArrayList<HashMap<String,
* String>> arraylist) { this.cntx = context; data = arraylist; imageLoader
* = new ImageLoader(context); }
*/
public ListViewAdapter2(Context context,
ArrayList<String> taskid,
ArrayList<String> taskname,
ArrayList<String> taskdetail) {
// TODO Auto-generated constructor stub
cntx = context;
t_id=taskid;
t_tname = taskname;
t_detail =taskdetail;
//Log.d("xyz", security_id.toString());
//ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).build();
//ImageLoader.getInstance().init(config);
alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setMessage("Do You Want To Call....");
// itemRating=itm_rating;
}
@Override
public int getCount() {
return t_id.size();
}
@Override
public Object getItem(int position) {
return t_id.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@SuppressWarnings("deprecation")
public View getView(final int position, View convertView, ViewGroup parent) {
@SuppressWarnings("unused")
final TextView taskname, taskdetail;
inflater = (LayoutInflater) cntx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater inflater = LayoutInflater.from(cntx);
convertView = inflater.inflate(R.layout.rawtask, parent, false);
/*ImageLoader imageLoader = ImageLoader.getInstance();
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
.cacheOnDisc(true).resetViewBeforeLoading(true)
.showImageForEmptyUri(loader)
.showImageOnFail(loader)
.showImageOnLoading(loader).build();*/
taskname= (TextView) convertView.findViewById(R.id.lvtaskname);
taskdetail= (TextView) convertView.findViewById(R.id.lvtaskdetails);
taskname.setText("taskName : "+t_tname.get(position));
taskdetail.setText("taskdetail: "+t_detail.get(position));
return convertView;
}
}
主要 Activity .java这是项目的最终 .java 文件
package com.example.sachin.listview;
public class Main2Activity extends Fragment {
public Main2Activity(){};
private static final String TAG_SUCCESS = "success";
JSONArray jsonarray;
JSONObject jsonobject;
ListView listview;
String img;
ListViewAdapter2 listadapter;
//ProgressDialog mProgressDialog;
ArrayList<HashMap<String, String>> arraylist;
private static String url_task = "http://10.0.2.2/portal/aFetchtask.php";
// private static String url_profile ="http://10.0.2.2/myapp/fetchmember.php";
JSONParser jParser = new JSONParser();
ArrayList<String> t_id = new ArrayList<String>();
ArrayList<String> t_tname = new ArrayList<String>();
ArrayList<String> t_detail = new ArrayList<String>();
View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
// don't look at this layout it's just a listView to show how to handle the keyboard
View view = inflater.inflate(R.layout.activity_main, container, false);
getActivity().setTitle("tasks");
new DownloadJSON().execute();
return view;
}
private class DownloadJSON extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
//mProgressDialog = new ProgressDialog(getActivity());
//mProgressDialog.setTitle("Please Wait");
// Set progressdialog message
//mProgressDialog.setMessage("Loading...");
//mProgressDialog.setIndeterminate(false);
// Show progressdialog
//mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... args) {
// Create an array
try {
arraylist = new ArrayList<HashMap<String, String>>();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("abc", "abc"));
JSONObject json = jParser.makeHttpRequest(url_task, "POST", params);
int success1 = Integer.parseInt(json.getString(TAG_SUCCESS));
Log.d("success", json.toString());
if (success1 == 0) {
Snackbar.make(view, "Not Data Found", Snackbar.LENGTH_LONG).show();
}
if (success1 == 1) {
JSONArray ownerObj = json.getJSONArray("tasks");
// arraylist = new ArrayList<HashMap<String, String>>();
// Retrieve JSON Objects from the given URL address
// Locate the array name in JSON
// jsonarray = jsonobject.getJSONArray("images");
for (int i = 0; i < ownerObj.length(); i++) {
// HashMap<String, String> map = new HashMap<String, String>();
jsonobject = ownerObj.getJSONObject(i);
// Retrive JSON Objects
//securityId.add(jsonobject.getString("security_id"));
// t_id.add(jsonobject.getString("t_id"));
t_tname.add(jsonobject.getString("t_tname"));
t_detail.add(jsonobject.getString("t_detail"));
// Number.add(jsonobject.getString("number"));
Log.d("DATA", jsonobject.toString());
//img="http://10.0.2.2/momskitchen/image/";
//proImage.add(img + jsonobject.getString("image"));
/* System.out.println(jsonobject.getString(TA));
System.out.println(g);*/
}
}
} catch (Exception e) {
}
return null;
}
@Override
protected void onPostExecute(Void args) {
listview = (ListView) getActivity().findViewById(R.id.listviewtask);
ListViewAdapter2 listadapter = new ListViewAdapter2(getActivity(), t_id, t_tname, t_detail);
// Set the adapter to the ListView
listview.setAdapter(listadapter);
// Close the progressdialog
//mProgressDialog.dismiss();
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
//add the values which need to be saved from the drawer to the bundle
// outState = result.saveInstanceState(outState);
super.onSaveInstanceState(outState);
}
}
最后一个文件是我的 api 文件..
<?php
include("connection.php");
$response = array();
// get all products from products table
$result = mysql_query("SELECT * FROM task") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["tasks"] = array();
while ($row = mysql_fetch_array($result))
{
$tasks = array();
$tasks["t_id"] = $row["t_id"];
$tasks["t_tname"] = $row["t_tname"];
$tasks["t_udetail"] = $row["t_udetail"];
// push single product into final response array
array_push($response["tasks"], $tasks);
}
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
}
else
{
// no products found
$response["success"] = 0;
$response["message"] = "No picture found";
// echo no users JSON
echo json_encode($response);
}
?>
这里所有文件都可用。但数据不是从数据库中获取的。请帮我解决这个问题..
最佳答案
存在很多编码错误。
protected Void doInBackground(Void... args) {}
返回 null 后,您可以将 null 值传递给 onPostExcute(Void args)
,您必须编写 get仅当您未返回任何响应时,才会在 doInBackground()
方法中完全休息。关于android - 我想从数据库中获取数据并将其显示在 ListView 上。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38736204/
我需要您在以下方面提供帮助。近一个月来,我一直在阅读有关任务和异步的内容。 我想尝试在一个简单的 wep api 项目中实现我新获得的知识。我有以下方法,并且它们都按预期工作: public Htt
我的可执行 jar 中有一个模板文件 (.xls)。不需要在运行时我需要为这个文件创建 100 多个副本(稍后将唯一地附加)。用于获取 jar 文件中的资源 (template.xls)。我正在使用
我在查看网站的模型代码时对原型(prototype)有疑问。我知道这对 Javascript 中的继承很有用。 在这个例子中... define([], function () { "use
影响我性能的前三项操作是: 获取滚动条 获取偏移高度 Ext.getStyle 为了解释我的应用程序中发生了什么:我有一个网格,其中有一列在每个单元格中呈现网格。当我几乎对网格的内容做任何事情时,它运
我正在使用以下函数来获取 URL 参数。 function gup(name, url) { name = name.replace(/[\[]/, '\\\[').replace(/[\]]/,
我最近一直在使用 sysctl 来做很多事情,现在我使用 HW_MACHINE_ARCH 变量。我正在使用以下代码。请注意,当我尝试获取其他变量 HW_MACHINE 时,此代码可以完美运行。我还认为
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 要求提供代码的问题必须表现出对所解决问题的最低限度的理解。包括尝试过的解决方案、为什么
由于使用 main-bower-files 作为使用 Gulp 的编译任务的一部分,我无法使用 node_modules 中的 webpack 来require 模块code> dir 因为我会弄乱当
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 5 年前。 Improve this qu
我使用 Gridlayout 在一行中放置 4 个元素。首先,我有一个 JPanel,一切正常。对于行数变大并且我必须能够向下滚动的情况,我对其进行了一些更改。现在我的 JPanel 上添加了一个 J
由于以下原因,我想将 VolumeId 的值保存在变量中: #!/usr/bin/env python import boto3 import json import argparse import
我正在将 MSAL 版本 1.x 更新为 MSAL-browser 的 Angular 。所以我正在尝试从版本 1.x 迁移到 2.X.I 能够成功替换代码并且工作正常。但是我遇到了 acquireT
我知道有很多关于此的问题,例如 Getting daily averages with pandas和 How get monthly mean in pandas using groupby但我遇到
This is the query string that I am receiving in URL. Output url: /demo/analysis/test?startDate=Sat+
我正在尝试使用 javascript 中的以下代码访问 Geoserver 层 var gkvrtWmsSource =new ol.source.ImageWMS({ u
API 需要一个包含授权代码的 header 。这就是我到目前为止所拥有的: var fullUrl = 'https://api.ecobee.com/1/thermostat?json=\{"s
如何获取文件中的最后一个字符,如果是某个字符,则删除它而不将整个文件加载到内存中? 这就是我目前所拥有的。 using (var fileStream = new FileStream("file.t
我是这个社区的新手,想出了我的第一个问题。 我正在使用 JSP,我成功地创建了 JSP-Sites,它正在使用jsp:setParameter 和 jsp:getParameter 具有单个字符串。
在回答 StoreStore reordering happens when compiling C++ for x86 @Peter Cordes 写过 For Acquire/Release se
我有一个函数,我们将其命名为 X1,它返回变量 Y。该函数在操作 .on("focusout", X1) 中使用。如何获取变量Y?执行.on后X1的结果? 最佳答案 您可以更改 Y 的范围以使其位于函
我是一名优秀的程序员,十分优秀!