1. android listView 過濾 不顯示提示區域
用ListView來載入數據的頁面不需要在ListView的外面再套上一個ScollView,因為ListView本身可以滾動顯示數據。有時我們頁面中除要用ListView顯示列表數據之外還要顯示其它數據,這時候就需要在整個頁面最個層套上一個Scollview,否則顯示就可能出現問題(比如在ListView上面已經有很多其它數據,顯示在手機上直接導致ListView看不見了,這時就要在整個屏幕布局加ScollView實現滑動界面),用過ScollView嵌套ListView的朋友都知道,在不做任務處理的情況下,ListView的數據只能顯示一行多一點點,其它的就看不到了,這個問題怎麼解決呢?通常我們可以有下面兩種方式:
1,計算高度:
private int totalHeight=0;
public static void setListViewHeight(ListView listView){
/*得到適配器*/
Aadpter adapter = listView.getAdapter();
/*遍歷控制項*/
for (int i = 0; i < adapter .getCount(); i++) {
View view = adapter .getView(i, null, listView);
/*測量一下子控制項的高度*/
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
totalHeight+=view.getMeasuredHeight();
}
/*控制項之間的間隙*/
totalHeight+=listView.getDividerHeight()*(listView.getCount()-1);
/*2、賦值給ListView的LayoutParams對象*/
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight;
listView.setLayoutParams(params);
}
2,重寫ListView的onMeasure:
public class WholeListView extends ListView {
public WholeListView (Context context) {
super(context);
}
public WholeListView (Context context, AttributeSet attrs) {
super(context, attrs);
}
public WholeListView (Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
當然上面兩個方法對GridView及Expandlistview也是有效的。
2. 我用searchview和listview做的安卓應用的一個搜索功能,怎麼才能把屏幕中的這個輸入的內容的黑色方塊去掉
自己寫 onQueryTextChange 里的方法,過濾數據
3. Android 刪除listview中的item
listview item的根布局中增加
android:descendantFocusability="blocksDescendants"
表示子控制項可以獲取焦點
這樣,就可以點擊item中的button了
這個代碼有點多,其實很簡單的
你就用自定義adapter 然後在getView方法中對每個item的button注冊一個點擊事件
4. 如何在ListView中添加過濾
var
i:integer;
begin
fori:=0toListView1.Items.Count-1do
begin
ifPos('你的字元串',ListView1.Items[i].Caption)>0then
找到
else
沒找到
end;
end;
5. android listview項如何實現中文過濾,類似如下效果:
呃。是要實現提示BA?
網上搜下代碼吧。。有點復雜。
6. android 獲取listview每一項的內容
//獲得選中項的HashMap對象
HashMap<String,String> map=(HashMap<String,String>)myListView.getItemAtPosition(arg2);
String tid=map.get("tid");
7. android開發 如何獲得listview裡面的內容
我給你一個地址吧!你去看看!http://ajava.org/course/j2me/16894.html!另外向你求教下,你的android程序調用web服務是怎麼實現的?我是用ksoap2 連接的webservice,取到的數據在用正則表達式過濾才能顯示,我感覺我的方式不對,但是找不到合適的,不知道可否給一下你的資料郵箱[email protected]!謝謝了!
final ArrayList<HashMap<String, Object>> users = new ArrayList<HashMap<String, Object>>();
for (int i = 0; i < 10; i++) {
HashMap<String, Object> user = new HashMap<String, Object>();
user.put("img", R.drawable.user);
user.put("username", "姓名(" + i+")");
user.put("age", (20 + i) + "");
users.add(user);
}
SimpleAdapter saImageItems = new SimpleAdapter(this,
users,// 數據來源
R.layout.user,//每一個user xml 相當ListView的一個組件
new String[] { "img", "username", "age" },
// 分別對應view 的id
new int[] { R.id.img, R.id.name, R.id.age });
// 獲取listview
ListView myListView =((ListView) findViewById(R.id.users));
myListView.setAdapter(saImageItems);
myListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
// TODO Auto-generated method stub
String aa=(String) users.get(arg2).get("username");
Toast.makeText(ListViewTest.this, "你點擊了第"+arg2+"項的"+aa,Toast.LENGTH_SHORT).show();
}
});
8. 如何快速過濾ListView控制項中重復記錄,10W條以上的數據
用ListView顯示10多萬的數據,顯然是不能用Items.Add這樣傳統的方法載入的,能把界面給拖死.使用OwnerData的話,數據是內存中構建的,只要演算法不是很差,依現在CPU的速度,合並同類項問題不大.
9. 怎樣添加數據到ListView後過濾重復
來源是資料庫的話可以考慮在取出來數據的時候就去重 例如: select distinct * form table
10. Android開發,SearchView過濾ListView,彈出類似Toast的黑框.來大神給個具體的解決辦法,要實測有效的!
public boolean onQueryTextChange(String newText) {
if (TextUtils.isEmpty(newText)) {
adapter.getFilter().filter("");
Log.i("Nomad", "onQueryTextChange Empty String");
placesListView.clearTextFilter();
} else {
//主要是這句寫上就沒黑框了
adapter.getFilter().filter(newText.toString());
}
return true;
}
public boolean onQueryTextSubmit(String query) {
Log.i("Nomad", "onQueryTextSubmit");
return false;
}