简体   繁体   English

滚动以在android列表视图中添加更多项目

[英]scroll to add more item in android list view

Here's my Listview item 这是我的Listview项目

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ImageView
    android:id="@+id/img"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="20dp"
    android:gravity="center_vertical"
    android:background="@drawable/starred" />

<TextView
    android:id="@+id/txt_company"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/img"
    android:paddingBottom="10dp"
    android:textColor="#25383C"
    android:singleLine="true"
    android:textStyle="bold" 
    android:textSize="16dp" />

<TextView
    android:id="@+id/txt_position"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/txt_company"
    android:layout_toRightOf="@+id/img"
    android:textColor="#25383C"
    android:singleLine="true"
    android:textStyle="bold" 
    android:textSize="16dp" />
<TextView
    android:id="@+id/txt_city"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/txt_position"
    android:layout_toRightOf="@+id/img"
    android:textColor="#25383C"
    android:textStyle="bold" 
    android:singleLine="true"
    android:textSize="16dp" />
<TextView
    android:id="@+id/txt_state"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/txt_city"
    android:layout_toRightOf="@+id/img"
    android:textColor="#25383C"
    android:textStyle="bold" 
    android:singleLine="true"
    android:textSize="16dp" />

   </RelativeLayout>\

and this is my list view 这是我的列表视图

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/main_bg"
>

<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="47dip" android:layout_alignParentTop="true"
    android:background="@drawable/tab_bar" android:id="@+id/rel_jobDesc">

    <TextView android:layout_width="wrap_content" android:id="@+id/txt_SEARCH_TITLE"
        android:layout_height="wrap_content" android:layout_centerInParent="true"
        android:text="" android:textStyle="bold" android:textSize="20dip"
        android:textColor="#fff"></TextView>
</RelativeLayout>
<ListView
   android:id="@+id/list"
   android:cacheColorHint="#00000000"
   android:layout_marginTop="60dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/job_match_bg" >

</ListView>

<Button
    android:id="@+id/btn_more"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@drawable/viewmore"
    android:layout_centerHorizontal="true"/>

 </RelativeLayout>

my java code is 我的java代码是

          Data datadap= new Data(this,company,position,city,state,pass_value,desc_str);
            listView.setAdapter(datadap);

and this is my getview 这是我的观点

 public View getView(int position, View convertView, ViewGroup parent) {
         final String description;
         LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
         View row;
         row=mInflater.inflate(R.layout.list_item, parent,false);
         txtcompany = (TextView) row.findViewById(R.id.txt_company);
         imageView = (ImageView) row.findViewById(R.id.img);
         txtPosition= (TextView) row.findViewById(R.id.txt_position);
         txtCity= (TextView) row.findViewById(R.id.txt_city);
         txtState= (TextView) row.findViewById(R.id.txt_state);
         txtcompany.setText("Company:  "+companyarray[position]);
         txtPosition.setText("Position: "+positonarray[position]);
         txtCity.setText("City: "+cityarray[position]);
         txtState.setText("State: "+statearray[position]);
         imageView.setTag(receiceValueOfAdapter.get(position));
         description= Descarray[position];
         db.openWritableDatabase();
         savedItems=db.getAllData(str_user);
 }

and now how we can implement pull down to refresh listview, my listview data coming from server. 现在如何实现下拉列表刷新列表视图,我的列表视图数据来自服务器。

I am new in android development Plz help me how we can develop 我是Android开发的新手,请Plz帮助我如何开发

Thank you in advance. 先感谢您。 And sorry for my bad English. 抱歉我的英语不好。

Call notifyDataSetChanged() on your Adapter. 在适配器上调用notifyDataSetChanged() You can do it on thread and call that thread after every 5 seconds(or as you want). 您可以在线程上执行此操作,然后每5秒(或根据需要)调用该线程。 You can watch this tutorial for better idea. 您可以观看教程以获得更好的主意。

Create a custom 'PullToRefreshListView' by extending ListView class, and in layout xml use that class. 通过扩展ListView类来创建自定义“ PullToRefreshListView”,并在布局xml中使用该类。

Refer here: https://github.com/johannilsson/android-pulltorefresh.git 请参阅此处: https : //github.com/johannilsson/android-pulltorefresh.git

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM