activity代码如下:package com.newlandsystem.FMCG;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;import com.newlandsytem.FMCG.common.DatabaseService;
import com.newlandsytem.FMCG.common.Model;
import com.newlandsytem.FMCG.common.Person;public class B032Activity extends Activity implements OnClickListener {
// 店名
private TextView shopName;
// ListView
private ListView listView;
// 结果集合
private List<Person> personsList;
// 查询共通
private DatabaseService databaseService;
// 分页共通
private Model mModel;
// 上页
private Button preButton;
// 下页
private Button nextButton;
// 完成按钮
private Button completeButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// databaseService
databaseService = new DatabaseService(this);
// 结果集
personsList = new ArrayList<Person>();
// Intent
Intent intent = this.getIntent();
// Bundle
Bundle bundle = intent.getExtras();
// B031店名
String name = bundle.getString("shopName");
// B031配送区分
String sendCode = bundle.getString("shopCode");
setContentView(R.layout.b032);
shopName = (TextView) findViewById(R.id.shopName_B032);
listView = (ListView) findViewById(R.id.listView_032);
completeButton = (Button)findViewById(R.id.completeButton_032);
shopName.setText(name + sendCode);
// 创建一个Model的对象,首页,并且每页显示3个Item项
mModel = new Model(0, 3);
// 查询到的是第0页的3个数据
personsList = databaseService.getScrollData(
mModel.getIndex() * mModel.getView_Count(),
mModel.getView_Count());
List<HashMap<String, String>> data = new ArrayList<HashMap<String,String>>();
for(Person person:personsList){
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", person.getName());
map.put("count", "1");
data.add(map);
}
// 根据参数创建一个TestListAdapter对象,并设给ListView
SimpleAdapter adapter = new SimpleAdapter(B032Activity.this, data,
R.layout.b032_listview, new String[] {"name","count"}, new int[]{R.id.shopName_b032_listview,R.id.count_b032_listview});
listView.setAdapter(adapter);
preButton = (Button) findViewById(R.id.previousButton_032);
nextButton = (Button) findViewById(R.id.nextButton_032);
// 设置翻页按钮监听
preButton.setOnClickListener(this);
nextButton.setOnClickListener(this);
completeButton.setOnClickListener(this);
checkPageButton();
} @Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.previousButton_032:
// 上页
mModel.setIndex(mModel.getIndex() - 1);
personsList = databaseService.getScrollData(mModel.getIndex()
* mModel.getView_Count(), mModel.getView_Count());
List<HashMap<String, String>> data = new ArrayList<HashMap<String,String>>();
for(Person person:personsList){
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", person.getName());
map.put("count", "1");
data.add(map);
}
// 根据参数创建一个TestListAdapter对象,并设给ListView
SimpleAdapter adapter = new SimpleAdapter(B032Activity.this, data,
R.layout.b032_listview, new String[] {"name","count"}, new int[]{R.id.shopName_b032_listview,R.id.count_b032_listview});
listView.setAdapter(adapter);
checkPageButton();
break;
case R.id.nextButton_032:
// 下页
mModel.setIndex(mModel.getIndex() + 1);
personsList = databaseService.getScrollData(mModel.getIndex()
* mModel.getView_Count(), mModel.getView_Count());
List<HashMap<String, String>> data2 = new ArrayList<HashMap<String,String>>();
for(Person person:personsList){
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", person.getName());
map.put("count", "1");
data2.add(map);
}
// 根据参数创建一个TestListAdapter对象,并设给ListView
SimpleAdapter adapter2 = new SimpleAdapter(B032Activity.this, data2,
R.layout.b032_listview, new String[] {"name","count"}, new int[]{R.id.shopName_b032_listview,R.id.count_b032_listview});
listView.setAdapter(adapter2);
checkPageButton();
break;
case R.id.completeButton_032:
// listView.
default:
break;
}
} /**
* 翻页按钮可用检查
*/
private void checkPageButton() {
if (mModel.getIndex() <= 0) {
preButton.setEnabled(false);
nextButton.setEnabled(true);
} else if (databaseService.getCount() - mModel.getIndex()
* mModel.getView_Count() <= mModel.getView_Count()) {
nextButton.setEnabled(false);
preButton.setEnabled(true);
} else {
preButton.setEnabled(true);
nextButton.setEnabled(true);
}
}
}问题:
分页已经好使了,每一行是一个textview和edittext。但是edittext有个问题,输入内容之后页面貌似重新刷了下,导致无法输入。但是debug也没走代码啊,怎么回事,求大神
import java.util.HashMap;
import java.util.List;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;import com.newlandsytem.FMCG.common.DatabaseService;
import com.newlandsytem.FMCG.common.Model;
import com.newlandsytem.FMCG.common.Person;public class B032Activity extends Activity implements OnClickListener {
// 店名
private TextView shopName;
// ListView
private ListView listView;
// 结果集合
private List<Person> personsList;
// 查询共通
private DatabaseService databaseService;
// 分页共通
private Model mModel;
// 上页
private Button preButton;
// 下页
private Button nextButton;
// 完成按钮
private Button completeButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// databaseService
databaseService = new DatabaseService(this);
// 结果集
personsList = new ArrayList<Person>();
// Intent
Intent intent = this.getIntent();
// Bundle
Bundle bundle = intent.getExtras();
// B031店名
String name = bundle.getString("shopName");
// B031配送区分
String sendCode = bundle.getString("shopCode");
setContentView(R.layout.b032);
shopName = (TextView) findViewById(R.id.shopName_B032);
listView = (ListView) findViewById(R.id.listView_032);
completeButton = (Button)findViewById(R.id.completeButton_032);
shopName.setText(name + sendCode);
// 创建一个Model的对象,首页,并且每页显示3个Item项
mModel = new Model(0, 3);
// 查询到的是第0页的3个数据
personsList = databaseService.getScrollData(
mModel.getIndex() * mModel.getView_Count(),
mModel.getView_Count());
List<HashMap<String, String>> data = new ArrayList<HashMap<String,String>>();
for(Person person:personsList){
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", person.getName());
map.put("count", "1");
data.add(map);
}
// 根据参数创建一个TestListAdapter对象,并设给ListView
SimpleAdapter adapter = new SimpleAdapter(B032Activity.this, data,
R.layout.b032_listview, new String[] {"name","count"}, new int[]{R.id.shopName_b032_listview,R.id.count_b032_listview});
listView.setAdapter(adapter);
preButton = (Button) findViewById(R.id.previousButton_032);
nextButton = (Button) findViewById(R.id.nextButton_032);
// 设置翻页按钮监听
preButton.setOnClickListener(this);
nextButton.setOnClickListener(this);
completeButton.setOnClickListener(this);
checkPageButton();
} @Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.previousButton_032:
// 上页
mModel.setIndex(mModel.getIndex() - 1);
personsList = databaseService.getScrollData(mModel.getIndex()
* mModel.getView_Count(), mModel.getView_Count());
List<HashMap<String, String>> data = new ArrayList<HashMap<String,String>>();
for(Person person:personsList){
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", person.getName());
map.put("count", "1");
data.add(map);
}
// 根据参数创建一个TestListAdapter对象,并设给ListView
SimpleAdapter adapter = new SimpleAdapter(B032Activity.this, data,
R.layout.b032_listview, new String[] {"name","count"}, new int[]{R.id.shopName_b032_listview,R.id.count_b032_listview});
listView.setAdapter(adapter);
checkPageButton();
break;
case R.id.nextButton_032:
// 下页
mModel.setIndex(mModel.getIndex() + 1);
personsList = databaseService.getScrollData(mModel.getIndex()
* mModel.getView_Count(), mModel.getView_Count());
List<HashMap<String, String>> data2 = new ArrayList<HashMap<String,String>>();
for(Person person:personsList){
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", person.getName());
map.put("count", "1");
data2.add(map);
}
// 根据参数创建一个TestListAdapter对象,并设给ListView
SimpleAdapter adapter2 = new SimpleAdapter(B032Activity.this, data2,
R.layout.b032_listview, new String[] {"name","count"}, new int[]{R.id.shopName_b032_listview,R.id.count_b032_listview});
listView.setAdapter(adapter2);
checkPageButton();
break;
case R.id.completeButton_032:
// listView.
default:
break;
}
} /**
* 翻页按钮可用检查
*/
private void checkPageButton() {
if (mModel.getIndex() <= 0) {
preButton.setEnabled(false);
nextButton.setEnabled(true);
} else if (databaseService.getCount() - mModel.getIndex()
* mModel.getView_Count() <= mModel.getView_Count()) {
nextButton.setEnabled(false);
preButton.setEnabled(true);
} else {
preButton.setEnabled(true);
nextButton.setEnabled(true);
}
}
}问题:
分页已经好使了,每一行是一个textview和edittext。但是edittext有个问题,输入内容之后页面貌似重新刷了下,导致无法输入。但是debug也没走代码啊,怎么回事,求大神
解决方案 »
- 像来电通的这个功能怎么实现,有图
- 请教--android调用webservice时,httptransportse.call 很慢
- 请教android数据库操作的问题
- emulator.exe遇到问题需要关闭-----新手需要帮忙
- 没有SD卡如何自动更新软件?
- htc android开发待遇如何?
- 如何控制通过addView动态添加到laylout中的view的位置
- Android 文件读写问题
- 自定义的分享功能,点击分享按钮后,要等一段时间才能将对话框显示出来,如何解决?
- 我想写一个APP,视频监控surfaceview能不能实现
- ListView 中 Item获取焦点
- 含webview的java文件如何调用javascript方法,在线等
页面刷新了,我以为重载页面了,debug他也不走代码,说明不是重载页面导致无法输入
package Adapter;import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;import com.android.Book.R;public class GalleryAdapter extends BaseAdapter {
private Context mContext;
private int[]array;
private LayoutInflater inflater;
public GalleryAdapter(Context context,int[]array) {
// TODO Auto-generated constructor stub
this.mContext=context;
this.array=array;
this.inflater=LayoutInflater.from(mContext);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return array.length;
} @Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
} @Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder;
if(convertView==null){
convertView=inflater.inflate(R.layout.backpicker, null);
holder=new Holder();
holder.view=(ImageView)convertView.findViewById(R.id.backgroud_picker);
holder.view.setImageResource(array[position]);
convertView.setTag(holder);
}
else{
holder=(Holder) convertView.getTag();
}
return convertView;
}
class Holder{
ImageView view;
}
}
不过ListView中的所有item都有自已的OnItemClickListener,而如果在item中放入需要获得焦点控件,那么需要对ListView控制进行重写,阻止OnItemClickListener的事件接收,这也就意味着,ListView只能作为一个滚动列表了,而不能触发点击事件。
邮箱:
[email protected]
谢谢了。
我帮你找了一篇demo,可以实现分页,但是ListView要有一个editText,倒是没有,你可以加上去
http://www.eoeandroid.com/forum.php?mod=viewthread&tid=52761
剪切了一部分代码:public void onScroll(AbsListView v, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
Log.i(TAG , "Scroll>>>first: " + firstVisibleItem + ", visible: " + visibleItemCount + ", total: " + totalItemCount);
lastItem = firstVisibleItem + visibleItemCount - 1;
Log.i(TAG , "Scroll>>>lastItem:" + lastItem);
//显示50条ListItem,即0-49,因为onScroll是在“滑动”执行过之后才触发,所以用adapter.count<=41作条件
if (adapter.count<=41) {
if (firstVisibleItem+visibleItemCount==totalItemCount) {
adapter.count += 10;
adapter.notifyDataSetChanged();
listView.setSelection(lastItem);
int currentPage=adapter.count/10;
Toast.makeText(getApplicationContext(), "第"+currentPage+"页", Toast.LENGTH_LONG).show();
}
}
else {
listView.removeFooterView(loadingLayout);
}
}
@Override
public void onScrollStateChanged(AbsListView v, int state) {
if (lastItem == adapter.count && state == OnScrollListener.SCROLL_STATE_IDLE) {
Log.i(TAG,"ScrollStateChanged>>>state:"+state+"lastItem:" + lastItem);
//显示50条ListItem,即0-49,因为onScrollStateChanged是在“拖动滑动”执行过之后才触发,所以用adapter.count<=41作条件
if (adapter.count<=41) {
adapter.count += 10;
adapter.notifyDataSetChanged();
} }
}我很欣赏你这种不卑不亢的精神,但是别人也没有随你的任务而变动,只有我这种人才会发表这样的气话,下次可能的,我一定会像12楼说的那样把你忽略
整了2天了,实在整不出来了,迫不得已。我不是那种坐等代码的。