请描述listview baseadapterr优化策略,为什么要这样

Android 学习笔记-baseadapter的优化_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
Android 学习笔记-baseadapter的优化
上传于||暂无简介
阅读已结束,如果下载本文需要使用1下载券
想免费下载本文?
下载文档到电脑,查找使用更方便
还剩2页未读,继续阅读
你可能喜欢BaseAdapter不更新是怎么回事
这个问题纠结我很久了,那位大虾要是看到了,帮我解决一下,谢谢了问题出在public void onTabActivityResult(int requestCode, int resultCode, Intent data) 这个方法里,在这个方法里调用
adapter = new ContactMainAdapter(AddNewActivity.this, list);
& & & & & & & & & & & & & & & & listView.setAdapter(adapter);
& & & & & & & & & & & & & & & & adapter.notifyDataSetChanged();
这样死活不更新,而不在这个方法里调用addDataSource()这个方法,是可以正常显示数据刷新的,我在里面这样调用这个方法也没用
下面这个是TabHost的那个Activity一段代码
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
& & & & // 获取当前活动的Activity实例
& & & & @SuppressWarnings(&deprecation&)
& & & & & & & & Activity subActivity = manager.getCurrentActivity();
& & & & //判断是否实现返回值接口
& & & & if (subActivity instanceof OnTabActivityResultListener) {
& & & & & & //获取返回值接口实例
& & & & & & OnTabActivityResultListener listener = (OnTabActivityResultListener) subA
& & & & & & //转发请求到子Activity
& & & & & & listener.onTabActivityResult(requestCode, resultCode, data);
& & & & super.onActivityResult(requestCode, resultCode, data);
& & & & public interface OnTabActivityResultListener {
& & & & & & & & &public void onTabActivityResult(int requestCode, int resultCode, Intent data);
& & & & & & & & }
package com.vzo.eightpartycall.
import java.util.ArrayL
import java.util.L
import android.app.A
import android.app.AlertD
import android.app.D
import android.app.LocalActivityM
import android.content.I
import android.os.B
import android.os.H
import android.os.M
import android.util.L
import android.view.LayoutI
import android.view.V
import android.view.View.OnClickL
import android.view.ViewS
import android.view.W
import android.view.WindowM
import android.widget.AdapterV
import android.widget.AdapterView.OnItemLongClickL
import android.widget.B
import android.widget.EditT
import android.widget.ImageB
import android.widget.LinearL
import android.widget.ListV
import android.widget.RelativeL
import android.widget.TextV
import android.widget.T
import com.vzo.eightpartycall.R;
import com.vzo.eightpartycall.activity.MainActivity.OnTabActivityResultL
import com.vzo.eightpartycall.adapter.ContactMainA
import com.vzo.eightpartycall.bean.ContactB
public class AddNewActivity extends Activity implements OnClickListener,OnTabActivityResultListener {
& & & & private static final String TAG = AddNewActivity.class.getSimpleName();
& & & & private TextView tv_
& & & & private Button bt_cacel, bt_add, bt_softKey, add_
& & & & private ListView listV
& & & & private ImageButton ib_sms, ib_call, ib_
& & & & private RelativeL
& & & & private LinearLayout llayoutB
& & & & private LinearLayout topL
& & & & private Dialog smsD
& & & & private View smsV
& & & & private EditText ed_title, ed_month, ed_day, ed_
& & & & private EditText ed_emcee, ed_bafanghao, ed_passW
& & & & private Button bt_ensure, bt_
& & & & private ViewS
& & & & private List&ContactBean& list = new ArrayList&ContactBean&();
& & & & private ContactMainA
& & & & private Handler handler = new Handler(){
& & & & & & & & public void handleMessage(Message msg) {
& & & & & & & & & & & & switch (msg.what) {
& & & & & & & & & & & & case 1:
& & & & & & & & & & & & & & & & addDataSource();
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & default:
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & }
& & & & & & & & };
& & & & };
& & & & @Override
& & & & protected void onCreate(Bundle savedInstanceState) {
& & & & & & & & // TODO Auto-generated method stub
& & & & & & & & super.onCreate(savedInstanceState);
& & & & & & & & requestWindowFeature(Window.FEATURE_NO_TITLE);
& & & & & & & & Log.i(TAG,&onCreate&);
& & & & & & & & setContentView(R.layout.addnew);
& & & & & & & & initView();
// & & & & & & & &addDataSource();
& & & & & & & &&
& & & & private void initView() {
& & & & & & & & tv_minute = (TextView) findViewById(R.id.avariable_minute);
& & & & & & & & bt_cacel = (Button) findViewById(R.id.topCancelButton);
& & & & & & & & bt_cacel.setOnClickListener(this);
& & & & & & & & bt_add = (Button) findViewById(R.id.topAddButton);
& & & & & & & & bt_add.setOnClickListener(this);
& & & & & & & & bt_softKey = (Button) findViewById(R.id.topSoftButton);
& & & & & & & & bt_softKey.setOnClickListener(this);
& & & & & & & &&
& & & & & & & & ib_sms = (ImageButton) findViewById(R.id.smsImageButton);
& & & & & & & & ib_sms.setOnClickListener(this);
& & & & & & & & ib_call = (ImageButton) findViewById(R.id.callImageButton);
& & & & & & & & ib_call.setOnClickListener(this);
& & & & & & & & ib_collet = (ImageButton) findViewById(R.id.collectImageButton);
& & & & & & & & ib_collet.setOnClickListener(this);
& & & & & & & &&
& & & & & & & & listView = (ListView) findViewById(R.id.listView);
& & & & & & & &&
& & & & & & & & relayout = (RelativeLayout) findViewById(R.id.relayout);
& & & & & & & & add_contact = (Button) findViewById(R.id.addContact);
& & & & & & & & add_contact.setOnClickListener(this);
& & & & & & & &&
& & & & & & & & llayoutButton = (LinearLayout) findViewById(R.id.llayoutButton);
& & & & & & & & topLayout = (LinearLayout) findViewById(R.id.toplayout);
& & & & & & & &&
& & & & & & & &&
& & & & private void addDataSource(){
& & & & & & & & Log.i(&lanjianlong&,&addDataSource&);
& & & & & & & &&
& & & & & & & & for (int i = 0; i & 10; i++) {
& & & & & & & & & & & & ContactBean cb = new ContactBean();
& & & & & & & & & & & & cb.setDisplayName(&name&+i);
& & & & & & & & & & & & cb.setPhoneNum(&123456&+i);
& & & & & & & & & & & & list.add(cb);
& & & & & & & & }
& & & & & & & &&
& & & & & & & & adapter = new ContactMainAdapter(AddNewActivity.this, list);
& & & & & & & & listView.setAdapter(adapter);
& & & & & & & &&
& & & & & & & & listView.setOnItemLongClickListener(new OnItemLongClickListener() {
& & & & & & & & & & & & @Override
& & & & & & & & & & & & public boolean onItemLongClick(AdapterView&?& arg0,
& & & & & & & & & & & & & & & & & & & & View arg1, int arg2, long arg3) {
& & & & & & & & & & & & & & & & // TODO Auto-generated method stub
& & & & & & & & & & & & & & & & if(adapter.isButtonGone)
& & & & & & & & & & & & & & & & & & & & adapter.isButtonGone =
& & & & & & & & & & & & & & & & else
& & & & & & & & & & & & & & & & & & & & adapter.isButtonGone =
& & & & & & & & & & & & & & & &&
& & & & & & & & & & & & & & & & adapter.notifyDataSetChanged();
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & }
& & & & & & & & });
& & & & & & & &&
& & & & & & & & relayout.setVisibility(View.GONE);
// & & & & & & & &llayoutButton.setVisibility(View.GONE);
// & & & & & & & &add_contact.setVisibility(View.GONE);
& & & & & & & & listView.setVisibility(View.VISIBLE);
& & & & & & & & adapter.notifyDataSetChanged();
& & & & @Override
& & & & public void onClick(View v) {
& & & & & & & & // TODO Auto-generated method stub
& & & & & & & & Intent intent =
& & & & & & & & switch (v.getId()) {
& & & & & & & & case R.id.topCancelButton:
& & & & & & & & & & & & if(list != null && adapter != null){
& & & & & & & & & & & & & & & & list.clear();
& & & & & & & & & & & & & & & & adapter.setDateList(list);
& & & & & & & & & & & & & & & & adapter.notifyDataSetChanged();
& & & & & & & & & & & & }
& & & & & & & & & & & &
& & & & & & & & case R.id.topAddButton:
& & & & & & & & & & & & intent = new Intent();
& & & & & & & & & & & & intent.putExtra(&where&, &AddNewActivity&);
& & & & & & & & & & & & intent.setClass(AddNewActivity.this, InviteFriendActivity.class);
& & & & & & & & & & & & getParent().startActivityForResult(intent, 1);
& & & & & & & & & & & &
& & & & & & & & case R.id.topSoftButton:
& & & & & & & & & & & & getWindow().setSoftInputMode
& & & & & & & & & & & & (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
& & & & & & & & & & & &
& & & & & & & & case R.id.smsImageButton:
& & & & & & & & & & & & smsView = LayoutInflater.from(AddNewActivity.this).inflate(R.layout.sms_model, null);
// & & & & & & & & & & & &smsView.setVisibility(View.VISIBLE);
// & & & & & & & & & & & &listView.setVisibility(View.GONE);
// & & & & & & & & & & & &relayout.setVisibility(View.GONE);
// & & & & & & & & & & & &topLayout.setVisibility(View.GONE);
& & & & & & & & & & & &&
// & & & & & & & & & & & &stub = (ViewStub) findViewById(R.id.smsview);
// & & & & & & & & & & & &stub.inflate();
& & & & & & & & & & & &&
& & & & & & & & & & & & ed_title = (EditText) smsView.findViewById(R.id.ed_title);
& & & & & & & & & & & & ed_month = (EditText) smsView.findViewById(R.id.ed_month);
& & & & & & & & & & & & ed_day = (EditText) smsView.findViewById(R.id.ed_day);
& & & & & & & & & & & & ed_hour = (EditText) smsView.findViewById(R.id.ed_hour);
& & & & & & & & & & & & ed_emcee = (EditText) smsView.findViewById(R.id.ed_emcee);
& & & & & & & & & & & & ed_bafanghao = (EditText) smsView.findViewById(R.id.ed_bafanghao);
& & & & & & & & & & & & ed_passWord = (EditText) smsView.findViewById(R.id.ed_password);
& & & & & & & & & & & &&
& & & & & & & & & & & & bt_ensure = (Button) smsView.findViewById(R.id.bt_ensure);
& & & & & & & & & & & & bt_ensure.setOnClickListener(this);
& & & & & & & & & & & &&
& & & & & & & & & & & & bt_cancel = (Button) smsView.findViewById(R.id.bt_cancel);
& & & & & & & & & & & & bt_cancel.setOnClickListener(this);
& & & & & & & & & & & &&
& & & & & & & & & & & &&
& & & & & & & & & & & & AlertDialog.Builder builder = new AlertDialog.Builder(AddNewActivity.this);
& & & & & & & & & & & & builder.setView(smsView);
& & & & & & & & & & & & smsDialog = builder.create();
& & & & & & & & & & & & smsDialog.show();
& & & & & & & & & & & &
& & & & & & & & case R.id.callImageButton:
& & & & & & & & & & & & intent = new Intent();
& & & & & & & & & & & & intent.putExtra(&where&, &AddNewActivity&);
& & & & & & & & & & & & intent.setClass(AddNewActivity.this, CallPhoneActivity.class);
& & & & & & & & & & & & startActivity(intent);
& & & & & & & & & & & &
& & & & & & & & case R.id.collectImageButton:
& & & & & & & & & & & &&
& & & & & & & & & & & &
& & & & & & & & case R.id.addContact:
& & & & & & & & & & & & intent = new Intent();
& & & & & & & & & & & & intent.putExtra(&where&, &AddNewActivity&);
& & & & & & & & & & & & intent.setClass(AddNewActivity.this, InviteFriendActivity.class);
& & & & & & & & & & & & getParent().startActivityForResult(intent, 1);
& & & & & & & & & & & &
& & & & & & & & case R.id.bt_ensure:
// & & & & & & & & & & & &smsView.setVisibility(View.GONE);
// & & & & & & & & & & & &topLayout.setVisibility(View.VISIBLE);
& & & & & & & & & & & & smsDialog.dismiss();
& & & & & & & & & & & & listView.setVisibility(View.VISIBLE);
& & & & & & & & & & & & Toast.makeText(AddNewActivity.this, &ensure is onClick&, Toast.LENGTH_SHORT).show();
& & & & & & & & & & & &
& & & & & & & & case R.id.bt_cancel:
// & & & & & & & & & & & &smsView.setVisibility(View.GONE);
// & & & & & & & & & & & &Log.i(&lanjianlong&,&list, listView = &+listView);
// & & & & & & & & & & & &listView.setVisibility(View.VISIBLE);
// & & & & & & & & & & & &topLayout.setVisibility(View.VISIBLE);
& & & & & & & & & & & & smsDialog.dismiss();
& & & & & & & & & & & & Toast.makeText(AddNewActivity.this, &cnacel is onClick&, Toast.LENGTH_SHORT).show();
& & & & & & & & & & & &
& & & & & & & & default:
& & & & & & & & & & & &
& & & & & & & & }
& & & & @Override
& & & & public void onTabActivityResult(int requestCode, int resultCode, Intent data) {
& & & & & & & & // TODO Auto-generated method stub
& & & & & & & & Log.i(&lanjianlong&,&AddNewActivity, onTabActivityResult(), data = &+data);
& & & & & & & & Log.i(&lanjianlong&,&AddNewActivity, onTabActivityResult, requestCode = &+requestCode+&, resultCode = &+resultCode+&, Activity.RESULT_OK=&+Activity.RESULT_OK);
& & & & & & & & addDataSource();//这个方法不在这里调用是可以显示数据的,在此调用,怎么都没反应,这个方法是放在这里测试的
& & & & & & & &&
//下面的是另一个Activity返回的数据,数据可以返回,数据有打印出来
& & & & & & & & if(requestCode == 1){
& & & & & & & & & & & & if(data == null)
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & Bundle bd = data.getExtras();
& & & & & & & & & & & & list.clear();
& & & & & & & & & & & & List&ContactBean& tempList = (List&ContactBean&) bd.getSerializable(&lists&);
& & & & & & & & & & & & ContactBean cb =
& & & & & & & & & & & & for (int i = 0; i & tempList.size(); i++) {
& & & & & & & & & & & & & & & & cb = new ContactBean();
& & & & & & & & & & & & & & & & cb.setDisplayName(tempList.get(i).getDisplayName());
& & & & & & & & & & & & & & & & cb.setPhoneNum(tempList.get(i).getPhoneNum());
& & & & & & & & & & & & & & & & list.add(cb);
& & & & & & & & & & & & & & & & Log.i(&lanjianlong&,&AddNewActivity, onTabActivityResult, name, phone = &+tempList.get(i).getDisplayName()+&, &
& & & & & & & & & & & & & & & & +tempList.get(i).getPhoneNum()+&, & list.size() = &+list.size());
& & & & & & & & & & & & }
& & & & & & & & & & & & Log.i(&lanjianlong&,&onTabActivityResult, tempList = &+tempList);
& & & & & & & & & & & & if(list.size() & 0){
& & & & & & & & & & & & & & & & listView =
& & & & & & & & & & & & & & & & listView = (ListView) findViewById(R.id.listView);
& & & & & & & & & & & & & & & & relayout.setVisibility(View.GONE);
& & & & & & & & & & & & & & & & listView.setVisibility(View.VISIBLE);
& & & & & & & & & & & & & & & & adapter = new ContactMainAdapter(AddNewActivity.this, list);//在此重新new 或者不new 效果都是一样的,数据就是不更新
& & & & & & & & & & & & & & & & listView.setAdapter(adapter);
& & & & & & & & & & & & & & & & adapter.notifyDataSetChanged();
& & & & & & & & & & & & & & & &&
& & & & & & & & & & & & & & & & Log.i(&lanjianlong&, &onTabActivityResult, list.size() = &+list.size());
& & & & & & & & & & & & & & & &&
& & & & & & & & & & & & }else{
& & & & & & & & & & & & & & & & relayout.setVisibility(View.VISIBLE);
& & & & & & & & & & & & & & & & listView.setVisibility(View.GONE);
& & & & & & & & & & & & & & & & Log.i(&lanjianlong&, &onTabActivityResult, &else&);
& & & & & & & & & & & & }
& & & & & & & & }
& & & & & & & &&
// & & & & & & & &super.onActivityResult(requestCode, resultCode, data);

我要回帖

更多关于 listview baseadapter 的文章

 

随机推荐