contentprovider怎么才能不重新查询一遍数据就能够刷新listview

contentprovider怎么才能不重新查询一遍数据就能够刷新listview,第1张

MainActivity 的内容
package comexampleandroidtest;
import androidappActivity;
import androidosBundle;
import androidviewGravity;
import androidviewView;
import androidviewViewOnClickListener;
import androidwidgetLinearLayout;
import androidwidgetListView;
import androidwidgetTextView;
public class MainActivity extends Activity implements OnClickListener {
ListView mListView;
TextViewAdapter mAdapter;
TextView notifyView;
TextView refreshItemView;
@Override
public void onClick(View v) {
switch (vgetId()) {
case 0x11: {
//使用一般方法刷新UI
String targetString = "2";
int targetIndex = -1;
// 1查找text内容为"2"的下标;
for (int j = 0; j < mListViewgetCount(); j++) {
String itemString = (String) mListViewgetItemAtPosition(j);
if (targetStringequals(itemString)) {
targetIndex = j;
break;
}
}
if (targetIndex >= 0) {
mAdaptersetGreenItem(targetIndex);
mAdapternotifyDataSetChanged();
}
}
break;
case 0x22: {
//使用高效的方法刷新UI(当然如果postion不在页面上,不需要刷新)
// 1我们想要修改text内容为"2"的Item的位置
String targetString = "2";
int targetIndex = -1;
for (int j = 0; j < mListViewgetCount(); j++) {
String itemString = (String) mListViewgetItemAtPosition(j);
if (targetStringequals(itemString)) {
targetIndex = j;
break;
}
}
if (targetIndex >= 0) {
mAdaptersetGreenItem(targetIndex);
int startShownIndex = mListViewgetFirstVisiblePosition();
int endShownIndex = mListViewgetLastVisiblePosition();
if (targetIndex >= startShownIndex
&& targetIndex <= endShownIndex) {
View view = mListViewgetChildAt(targetIndex
- startShownIndex);
mListViewgetAdapter()
getView(targetIndex, view, mListView);
}
}
}
break;
default:
break;
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
superonCreate(savedInstanceState);
LinearLayout outLayout = new LinearLayout(this);
outLayoutsetOrientation(LinearLayoutVERTICAL);
notifyView = new TextView(this);
notifyViewsetId(0x11);
notifyViewsetLayoutParams(new LinearLayoutLayoutParams(
LinearLayoutLayoutParamsMATCH_PARENT, 100));
notifyViewsetText("调用notifyDataSetChange刷新数据");
notifyViewsetGravity(GravityCENTER);
refreshItemView = new TextView(this);
refreshItemViewsetId(0x22);
refreshItemViewsetLayoutParams(new LinearLayoutLayoutParams(
LinearLayoutLayoutParamsMATCH_PARENT, 100));
refreshItemViewsetText("调用refresh Item刷新数据");
refreshItemViewsetGravity(GravityCENTER);
mListView = new ListView(this);
outLayoutaddView(notifyView);
outLayoutaddView(refreshItemView);
outLayoutaddView(mListView);
setContentView(outLayout);
mAdapter = new TextViewAdapter(this);
mListViewsetAdapter(mAdapter);
notifyViewsetOnClickListener(this);
refreshItemViewsetOnClickListener(this);
}
}

以上就是关于contentprovider怎么才能不重新查询一遍数据就能够刷新listview全部的内容,包括:contentprovider怎么才能不重新查询一遍数据就能够刷新listview、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/9462745.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存