如何在android中自动加载帖子

时间:2017-01-16 11:20:15

标签: android

我想要自动加载帖子当我们到达列表视图的末尾时,例如他们加载10到10。 我使用sqlite数据库并解决这个问题我在互联网上看到关于这个的教育帖子,我努力但不幸的是我不能这样做。 这是我的主要活动

public class MainActivity extends ListActivity {

private database db;
private String[] Name;
private String[] Teedad;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    db = new database(this);
    db.useable();
    refresher();
    setListAdapter(new AA());
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    ProgressDialog pd = new ProgressDialog(this);
    pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTA  L);
    pd.setMessage("لطفا کمی صبر کنید ...");
    pd.setCancelable(true);
    pd.setProgress(0);
    pd.show();
    Intent intent = new Intent(MainActivity.this, storys.class);
    intent.putExtra("season", Name[position]);
    MainActivity.this.startActivity(intent);
    pd.setProgress(100);
}

class AA extends ArrayAdapter<String> {
    public AA() {
        super(MainActivity.this, R.layout.raw_seasone, Name);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater in = getLayoutInflater();
        View row = in.inflate(R.layout.raw_seasone, parent, false);
        TextView name = (TextView) row.findViewById(R.id.name_season);
        TextView teedad = (TextView) row.findViewById(R.id.teedad_dastan);
        name.setText(Name[position]);
        teedad.setText(Teedad[position]);
        return (row);
    }
}

private void refresher() {
    db.open();
    int save = db.shomaresh_field("datastorys", "season");
    Name = new String[save];
    Teedad = new String[save];

    for (int i = 0; i < save; i++) {
        Name[i] = db.namayesh_fasl("datastorys", i);
        Teedad[i] = db.shomaresh_dastan("datastorys", Name[i].toString()) + "";
    }

    db.close();
}

}

所有必要的事项都在此活动中

1 个答案:

答案 0 :(得分:0)

您需要使用listview的offset属性。

你可以这样做:

Loading only 10 items in listview

  • rushank shah Stack Overflow