Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ListView不显示数据_Android - Fatal编程技术网

Android ListView不显示数据

Android ListView不显示数据,android,Android,我已经学习了教程,但我不明白为什么模拟器没有显示这些项目 以下是我的列表活动: public class MyListActivity extends ListActivity { private Timer myTimer; private boolean SetTimerOnResume=false; private ArrayList<HashMap<String,String>> chat=new ArrayList<HashMap<String,

我已经学习了教程,但我不明白为什么模拟器没有显示这些项目

以下是我的列表活动:

public class MyListActivity extends ListActivity {

private Timer myTimer;
private boolean SetTimerOnResume=false;

private ArrayList<HashMap<String,String>> chat=new ArrayList<HashMap<String,String>>();

private LazyAdapter adapter;

static final String Key_username="username_key";
static final String Key_email="email_key";
static final String Key_messageText="messageText_key";
static final String Key_messageDate="messageDate_key";

     @Override
      public void onCreate(Bundle savedInstance) {
         super.onCreate(savedInstance);
            setContentView(R.layout.lists);

            HttpRequest httpRequest=new HttpRequest("ReturnNewChatsToAdmin", "admin", "You" , "zawalarsa", "muazzamalii@hotmail.com");  
            String data=httpRequest.ExecuteRequest();
            httpRequest.ExecuteRequest();

            try {

                 JSONArray jsonarr=new JSONArray(data);

                for(int i=0;i<jsonarr.length();i++)
                {   
                    HashMap<String,String> hashMap=new HashMap<String,String>();

                    hashMap.put(MyListActivity.Key_username, jsonarr.getJSONObject(i).getString("username"));
                    hashMap.put(MyListActivity.Key_email, jsonarr.getJSONObject(i).getString("email"));
                    hashMap.put(MyListActivity.Key_messageText, jsonarr.getJSONObject(i).getString("chatText"));
                    hashMap.put(MyListActivity.Key_messageDate, jsonarr.getJSONObject(i).getString("chatDate"));

                    chat.add(hashMap);

                }

            ListView lv=(ListView)findViewById(android.R.id.list);
            adapter=new LazyAdapter(this,chat);
            lv.setAdapter(adapter);

          lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

            }
          });

            }
            catch(JSONException e)
            {
            }
     }

}
公共类MyListActivity扩展了ListActivity{
私人定时器;
私有布尔SetTimerOnResume=false;
private ArrayList chat=new ArrayList();
专用懒散适配器;
静态最终字符串键\u username=“username\u Key”;
静态最终字符串Key\u email=“email\u Key”;
静态最终字符串键\u messageText=“messageText\u Key”;
静态最终字符串键\u messageDate=“messageDate\u Key”;
@凌驾
创建时的公共void(Bundle savedInstance){
super.onCreate(savedInstance);
setContentView(R.layout.lists);
HttpRequest HttpRequest=新的HttpRequest(“ReturnNewChatsToAdmin”、“admin”、“You”、“zawalarsa”、”muazzamalii@hotmail.com");  
字符串数据=httpRequest.ExecuteRequest();
httpRequest.ExecuteRequest();
试一试{
JSONArray jsonarr=新的JSONArray(数据);
对于(int i=0;i
以下是输出:

更改这些行

HashMap<String,String> map=new HashMap<String, String>();
hashmap.get(position);
HashMap map=newhashmap();
获取(位置);

HashMap-map=HashMap.get(位置);

它会起作用的

ah thnx您为我节省了很多时间:当然我可以。在您的代码中,您使用map实例来填充getView()中的textview,但数据集由ArrayList hashmap持有。因此您需要检索持有信息的对象(hashmap.get(position);)并指定给用于填充textviewcheck if(view==null)而不是if(convertView==null)和than的映射实例check@AkashG区别是什么?您将视图初始化为view-view=convertView;但是通过if(convertView==null)检查条件再次,您将返回视图作为返回视图;请使用view或convertView。
<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp" >


 <LinearLayout
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:orientation="horizontal" >

 <TextView
     android:id="@+id/username"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_weight="11.74"
     android:textColor="#FFFF00"
     android:textSize="17sp"
     android:textStyle="bold"
      />

 <TextView
     android:id="@+id/chatdate"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_weight="11.74"
     android:textColor="#FFFF00"
     android:textSize="17sp"
     android:textStyle="bold"
     />

 </LinearLayout>

 <TextView
 android:id="@+id/email"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
  />

 <TextView android:id="@+id/message" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content"
 android:text="@string/Message"
 android:textStyle="bold"/>

<TextView android:id="@+id/messagetext" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content"
 />

</LinearLayout>
HashMap<String,String> map=new HashMap<String, String>();
hashmap.get(position);
HashMap<String,String> map= hashmap.get(position);