ListView中OnItemClickListener事件不能执行

Activity类:

private String[] mStrings2={"Title 01","Title 02"};
private String[] mStrings = {"Link to the image1", "Link to the image2"};

MyAdapter adapter;

        mainList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {              

            adapter=new LazyAdapter(this, mStrings, mStrings2);
            subList.setAdapter(adapternew);                       

        }
    });


MyAdapter class (MyAdapter.java)

    private Activity activity;
    private String[] data;
    private String[] data2;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 

//Constructor
public LazyAdapter(Activity a, String[] d, String[] mStrings2) {
        activity = a;
        data=d;
        data2=mStrings2;
        inflater = LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

当我点击第一个 List Item,我想把元素加载到第二个数组中。但是当执行程序后,获得NullPointerException异常。就是说ListView中OnItemClickListener事件不能执行。大家能指导下哪出错了吗?

12-04 14:21:42.499: E/AndroidRuntime(1429): java.lang.NullPointerException
12-04 14:21:42.499: E/AndroidRuntime(1429):     at com.java.hotelapp.Item_List$1.onItemClick(Item_List.java:106)
12-04 14:21:42.499: E/AndroidRuntime(1429):     at android.widget.AdapterView.performItemClick(AdapterView.java:282)
12-04 14:21:42.499: E/AndroidRuntime(1429):     at android.widget.AbsListView.performItemClick(AbsListView.java:1037)
12-04 14:21:42.499: E/AndroidRuntime(1429):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2449)
12-04 14:21:42.499: E/AndroidRuntime(1429):     at android.widget.AbsListView$1.run(AbsListView.java:3073)
12-04 14:21:42.499: E/AndroidRuntime(1429):     at android.os.Handler.handleCallback(Handler.java:587)
12-04 14:21:42.499: E/AndroidRuntime(1429):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-04 14:21:42.499: E/AndroidRuntime(1429):     at android.os.Looper.loop(Looper.java:132)
12-04 14:21:42.499: E/AndroidRuntime(1429):     at android.app.ActivityThread.main(ActivityThread.java:4123)
12-04 14:21:42.499: E/AndroidRuntime(1429):     at java.lang.reflect.Method.invokeNative(Native Method)
12-04 14:21:42.499: E/AndroidRuntime(1429):     at java.lang.reflect.Method.invoke(Method.java:491)
12-04 14:21:42.499: E/AndroidRuntime(1429):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
12-04 14:21:42.499: E/AndroidRuntime(1429):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
12-04 14:21:42.499: E/AndroidRuntime(1429):     at dalvik.system.NativeStart.main(Native Method)
Baby_Bonnie
Baby_Bonnie 当我点击First list item时,就NullPointerException。
7 年多之前 回复
franzhong
franzhong 哪句话空指针了?mainList?
7 年多之前 回复

3个回答

adapter=new LazyAdapter(this, mStrings, mStrings2);
subList.setAdapter(adapternew);
adapternew是啥,改为adapter试试

adapter=new LazyAdapter(this, mStrings, mStrings2);

传this不会报编译时错误???

A328240784
追风筝的孩子 你得明确知道你的空指针异常是哪个对象为Null
7 年多之前 回复
Baby_Bonnie
Baby_Bonnie 没有报错,就是点击First list item时,会报错NullPointerException。
7 年多之前 回复

subList是null,检查在哪里初始化的。
subList是null,检查在哪里初始化的。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
listview 的监听事件中无法显示toast

package com.example; import java.util.ArrayList; import java.util.HashMap; import android.app.ListActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; public class SimpleListViewWithTitle extends ListActivity { private static final String TAG="outputInformation"; private ListView listview; private String[] myTitle={"姓名:","性别:","年龄:","居住地:","邮箱:"}; private String[] myStr = {"MARES","男","25","北京","xuanyusong@gmail.com"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ArrayList<HashMap<String,Object>> arrayList= new ArrayList<HashMap<String,Object>>(); for(int i=0;i<myTitle.length;i++){ HashMap<String,Object> hashMap= new HashMap<String,Object>(); hashMap.put("myTitle", myTitle[i]); hashMap.put("myStr", myStr[i]); arrayList.add(hashMap); } listview = getListView(); SimpleAdapter adapter = new SimpleAdapter(this,arrayList,android.R.layout.simple_expandable_list_item_2,new String[]{"myTitle","myStr"},new int[]{android.R.id.text1,android.R.id.text2}); setListAdapter(adapter); listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position,long id) { //System.out.println("您选择了" + myTitle[position]+":"+myStr[position]); Toast.makeText(SimpleListViewWithTitle.this,"您选择了" + myTitle[position]+":"+myStr[position],Toast.LENGTH_LONG).show(); Log.i(SimpleListViewWithTitle.TAG,"您选择了" + myTitle[position]+":"+myStr[position]); } }); setContentView(listview); } }

关于android中listview点击item没有反应

public class MapActivity extends BasePagerActivity { private MapView mMapView = null; private BaiduMap mBaiduMap; private ListView map_menu_lv; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); initData(); } @Override public void initData() { base_tv_title.setText("街景秀"); SDKInitializer.initialize(getApplicationContext()); View view = View.inflate(MapActivity.this, R.layout.map, null); map_menu_lv = (ListView) view.findViewById(R.id.map_menu_lv); map_menu_lv.setAdapter(new MapMenuListViewAdapter(MapActivity.this)); weibo_menu.setVisibility(View.VISIBLE); weibo_menu.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub //Toast.makeText(MapActivity.this, "wo", 1).show(); map_menu_lv.setVisibility(View.VISIBLE); } }); mMapView = (MapView) view.findViewById(R.id.bmapView); mBaiduMap = mMapView.getMap(); MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(15.0f); mBaiduMap.setMapStatus(msu); **map_menu_lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub switch (arg2) { case 0: mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); break; case 1: mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE); break; case 2: if(mBaiduMap.isTrafficEnabled()){ mBaiduMap.setTrafficEnabled(false); }else{ mBaiduMap.setTrafficEnabled(true); } break; default: break;** } } }); base_fr.addView(view); } @Override protected void onDestroy() { super.onDestroy(); // 在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理 mMapView.onDestroy(); } @Override protected void onResume() { super.onResume(); // 在activity执行onResume时执行mMapView. onResume (),实现地图生命周期管理 mMapView.onResume(); } @Override protected void onPause() { super.onPause(); // 在activity执行onPause时执行mMapView. onPause (),实现地图生命周期管理 mMapView.onPause(); } } 请问标识出的部分为什么不能起到切换百度地图状态的功能?

如何获取GridView或ListView中的每一个view

如题,我想在gridview中的某一个指定的view中设置一个抖动的动画,但我发现如果是这样写: bankAdapter = new CustomGridAdapter(MainActivity.this, bankItems); bankGrid.setAdapter(bankAdapter); //动画 Animation shakeAnim = AnimationUtils.loadAnimation(MainActivity.this, R.anim.shake_x); //获取gridview中的第2个view RelativeLayout viewAnim =(RelativeLayout) bankGrid.getChildAt(2); if (viewAnim !=null) { ImageView img = (ImageView) viewAnim.findViewById(R.id.ItemImage) ; img.startAnimation(shakeAnim); } bankGrid.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } 这时viewAnim的返回值是为null ,动画无法执行。 如果改为下面这样子: bankAdapter = new CustomGridAdapter(MainActivity.this, bankItems); bankGrid.setAdapter(bankAdapter); bankGrid.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Animation shakeAnim = AnimationUtils.loadAnimation(MainActivity.this, R.anim.shake_x); RelativeLayout viewAnim =(RelativeLayout) bankGrid.getChildAt(2-bankGrid.getFirstVisiblePosition()); if (viewAnim !=null) { ImageView img = (ImageView) viewAnim.findViewById(R.id.ItemImage) ; img.startAnimation(shakeAnim); } } 那么在点击gridview中任意一项之后,第二个view就可以实现抖动的动画效果。 但是,我需要的是在没有点击gridview的情况下,即一进入应用,gridview中第二个view(按钮)就立即开始抖动,而不是监听点击事件后才执行。求问怎么才能实现??

当我点击ListView item时如何关闭AlertDialog?

下面是 dialog 代码,在 dialog 中有一个 ListView,我想在点击 ListView item 时关闭AlertDialog: public void createSearchDialog(final String[] Memo){ LayoutInflater factory = LayoutInflater.from(this); View searchView = factory.inflate(R.layout.seach_dialog, null); lv = (ListView) searchView.findViewById(R.id.search_list); lv.setAdapter(new MyPerformanceArrayAdapter(this, Memo, memo_PW)); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View view, int position,long arg3) { // TODO Auto-generated method stub /// close dialog } }); searchBuilder = new AlertDialog.Builder(this); searchBuilder.setTitle("Search") .setView(searchView) .setNegativeButton("Back", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub } }) .show(); } 我想在`onItemClick()`方法中加入代码 但是不能执行。 怎么处理?

自定义listview点击监听时好时坏,不灵敏,是怎么回事啊

开始以为是设置的监听无效,后来发现是可以点击的,点击很不好用,偶尔才能点击到,请问是什么原因啊 package net.bmvod.jukeboxv2; import android.animation.ValueAnimator; import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.Toast; /** * TODO: document your custom view class. */ public class LvListView extends ListView implements AbsListView.OnItemClickListener { /** * 显示在屏幕上多少个item */ private int showItemCount; /** * 每个item的高度 */ private int itemHeight; /** * 记录第一个显示的item */ /** * 从第几行执行动画 */ private int scaleFlagIndex = 0; /** * 是否到了最后一行 */ private boolean lastFlag = false; /** * 步骤 */ private int step = 0; /** * 步骤个数 */ private int stepCount; public LvListView(Context context) { this(context, null); } public LvListView(Context context, AttributeSet attrs) { this(context, attrs, 0); } /** * 构造方法中拿到自定义属性showViewCount,并设置滚动监听 * * @param context * @param attrs * @param defStyleAttr */ public LvListView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); //获取showViewCount TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.LvListView); showItemCount = typedArray.getInt(R.styleable.LvListView_showViewCount, 0); typedArray.recycle(); //设置一个滚动监听 // setOnScrollListener(this); setOnItemClickListener(this); } /** * 重写onLayout方法得到LvListview尺寸信息,并根据要显示的item个数计算出item高度并设置 * * @param changed * @param l * @param t * @param r * @param b */ @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); if (changed) { itemHeight = this.getHeight() / showItemCount; for (int i = 0; i < getChildCount(); i++) { LinearLayout layout = (LinearLayout) getChildAt(i); LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, itemHeight); layout.setLayoutParams(layoutParams); } stepCount = getAdapter().getCount(); } } /** * 禁用手指滑动 * * @param ev * @return */ /** * 设置滚动到指定item */ public void scrollToItem() { step++; if (step == stepCount) { step = 0; this.lastFlag = true; startScaleAnimator(getChildAt(scaleFlagIndex), 1.0f, 0.6f); this.smoothScrollToPositionFromTop(step, 0, 1000); } else { this.smoothScrollToPositionFromTop(step, 0, 500); } } /** * 缩放动画 * * @param view * @param start * @param end */ public void startScaleAnimator(final View view, float start, float end) { ValueAnimator animator = ValueAnimator.ofFloat(start, end); animator.setDuration(500); animator.start(); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float value = (float) animation.getAnimatedValue(); view.setScaleX(value); view.setScaleY(0.4f + (0.6f * value)); } }); } /* @Override public void onScrollStateChanged(AbsListView view, int scrollState) { Log.e("onScrollStateChanged", "scrollState--" + scrollState); if (scrollState == OnScrollListener.SCROLL_STATE_FLING) { if (!lastFlag) { startScaleAnimator(view.getChildAt(scaleFlagIndex), 1.0f, 0.6f); startScaleAnimator(view.getChildAt(scaleFlagIndex + 1), 0.6f, 1.0f); scaleFlagIndex = 2; } } else if (scrollState == OnScrollListener.SCROLL_STATE_IDLE && lastFlag) { this.lastFlag = false; //this.scaleFlag = true; scaleFlagIndex = 1; } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { Log.e("onScroll", "firstVisibleItem--" + firstVisibleItem); }*/ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { System.out.println(position); switch (position) { case 0: startScaleAnimator(view, 0.6f, 1.0f); break; case 1: startScaleAnimator(view, 0.6f, 1.0f); break; case 2: startScaleAnimator(view, 0.6f, 1.0f); break; } } } ``` ``` 这是我的代码,是根据网上的例子改的,自定义listview的监听很不好,原来是跟本不可以点击然后我在列表的配置文件里面加了android:clickable="true" 之后的效果见识点20次能监听到一次那种效果,求解决

ListView +HorizontalScrollView OnItem 冲突,麻烦各位大神帮忙看看,怎么解决网上大部分方法我都试过没用

1.布局文件如下 <HorizontalScrollView android:id="@+id/ScrollView1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:visibility="visible"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:visibility="visible"> <LinearLayout android:id="@+id/ll_stock" android:layout_width="match_parent" android:layout_height="30dp" android:orientation="horizontal" android:visibility="visible" > <TextView android:id="@+id/xh" android:layout_width="50dp" android:layout_height="30dp" android:text="序号" android:textSize="20sp" android:textColor="@color/black_textview" /> <TextView android:id="@+id/djbh" android:layout_width="90dp" android:layout_height="30dp" android:layout_weight="0.49" android:text="单据编号" android:textSize="20sp" android:textColor="@color/black_textview" /> <TextView android:id="@+id/ddbh" android:layout_width="90dp" android:layout_height="30dp" android:text="订单编号" android:textSize="20sp" android:textColor="@color/black_textview" android:layout_weight="0.20" /> <TextView android:id="@+id/tvwlbh" android:layout_width="90dp" android:layout_height="30dp" android:text="物料编号" android:textSize="20sp" android:textColor="@color/black_textview" android:layout_weight="0.24" /> <TextView android:id="@+id/wlmc" android:layout_width="90dp" android:layout_height="30dp" android:text="物料名称" android:textSize="20sp" android:textColor="@color/black_textview" android:layout_weight="0.24" /> <TextView android:id="@+id/lxdm" android:layout_width="90dp" android:layout_height="30dp" android:layout_weight="0.61" android:text="类型代码" android:textSize="20sp" android:textColor="@color/black_textview" /> <TextView android:id="@+id/lxmc" android:layout_width="90dp" android:layout_height="30dp" android:text="类型名称" android:textSize="20sp" android:textColor="@color/black_textview" android:layout_weight="0.23" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/black_textview" android:visibility="visible"/> <ListView android:id="@+id/stockin_zp" android:layout_width="match_parent" android:layout_height="match_parent" android:dividerHeight="1dp" android:divider="@color/black_textview" android:visibility="visible" > </ListView> </LinearLayout> </HorizontalScrollView> 2.Activity文件中写的是 //调用方法填入内容 listView = (ListView) findViewById(R.id.stockin_zp); adapter = new 原料入库Adapter(this, dataList); listView.setAdapter(adapter); new 获取原料入库Task().execute(); //列表选中一行数据 listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //点击执行 //获取选中行的单据编号 单据编号 = adapter.getItem(position).get单据编号(); //隐藏列表 显示输入框 ScrollView1.setVisibility(View.GONE); //显示 llxinxi.setVisibility(View.VISIBLE); } });

调用adapter的时候,会执行getcount且返回count>0,但就是不执行getView().

首先放代码: public View onCreateView() { Log.d(TAG, "onCreateView"); if (layout == null) { //add layout = new LinearLayout(activity); layout.setOrientation(LinearLayout.VERTICAL); layout.setBackgroundColor(Color.WHITE); listview = new ListView(activity); // listview.setDividerHeight(0); listview.setVerticalScrollBarEnabled(false); LinearLayout.LayoutParams listParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 0); layout.addView(listview, listParams); itemList = Global.toDoSrv.getAllData(false); Log.d(TAG, "itemList"+itemList.get(0).getTitle()); adapter = new ToDoListAdapters(activity,itemList); listview.setAdapter(adapter); updateList(); } if (listview.getCount() <= 0) { listview.setBackgroundColor(Color.WHITE); ImageView image = new ImageView(activity); LayoutParams mParams = new LayoutParams(198, 242); mParams.setMargins(172, 220, 0, 0); image.setLayoutParams(mParams); image.setMaxHeight(198); image.setMaxWidth(242); image.setBackgroundResource(R.drawable.none_todo_bg); layout.addView(image); } if (layout.getParent() != null) { ((ViewGroup) layout.getParent()).removeView(layout); } return layout; } private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { Log.d(TAG, "handleMessage:"+msg); switch (msg.what) { case MESSAGE_UPDATE_DATA: doUpdate(); break; case MESSAGE_UPDATE_LISTVIEW: updateAdapter(); break; } } }; private void updateList() { itemList = Global.toDoSrv.getAllData(true); adapter.notifyDataSetChanged(); } // 跟新 protected void doUpdate() { new Thread(new Runnable() { @Override public void run() { listNewTodo = Global.toDoSrv.getAllData(false); handler.sendEmptyMessage(MESSAGE_UPDATE_LISTVIEW); } }).start(); } // 刷新适配器 public void updateAdapter() { itemList.clear(); int count = listNewTodo.size(); for (int i = 0; i < count; ++i) { itemList.add(listNewTodo.get(i)); }; adapter.notifyDataSetChanged(); } private class ToDoListAdapters extends BaseAdapter { private NoteListActivity noteactivity; private List<ToDoItem> itemLists = new ArrayList<ToDoItem>(); public ToDoListAdapters(Context c,List<ToDoItem> itemList){ this.noteactivity = (NoteListActivity) c; this.itemLists = itemList; } @Override public int getCount() { if (itemLists == null) { Log.d(TAG, "ToDoListAdapters-->getCount-->itemLists == null"); return 0; } Log.d(TAG, "ToDoListAdapters-->getCount-->itemLists != null count:"+itemLists.size()); return itemLists.size(); } @Override public ToDoItem getItem(int arg0) { if (itemLists == null) { return null; } Log.d(TAG, "ToDoListAdapters-->getCount-->itemLists != null ToDoItem:"+itemLists.get(arg0)); return itemLists.get(arg0); } @Override public long getItemId(int arg0) { return arg0; } @Override public View getView(int position, View convertView, ViewGroup root) { Log.d(TAG, "ToDoListAdapters:getView"); ToDoItemView itemView; if (convertView == null) { itemView = new ToDoItemView(noteactivity); } else { itemView = (ToDoItemView) convertView; } ToDoItem item = getItem(position); itemView.setToDoItem(item); return itemView; } } public void update(boolean force) { if (adapter == null) { adapter = new ToDoListAdapters(activity,itemList); listview.setAdapter(adapter); adapter.notifyDataSetChanged(); listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position < adapter.getCount()) { // 从适配器中获取当前点击项的内容 } } }); } if (adapter != null && (adapter.getCount() < 1 || force)) { handler.sendEmptyMessageDelayed(MESSAGE_UPDATE_DATA, 500); } } 在调试的时候getcount会获得count>0,但getView()就是不执行,线程会影响getView()?这个问题郁闷了好久,求解答。。。。。

android Fragment 使用adapter时getView 方法不执行,在Activity下可以执行

在网上也看了很多相关文章了,还是没有解决,在Activity下使用此代码没有任何问题,数据可以显示,但是用了Fragment adapter的getView方法就一直不执行。 我觉得他们之间唯一的区别的就是context 和view 的不同,请大神指教 代码如下 public class BookSearchActivity extends Fragment { private BookSearchService service; private List<Books> list; private String result; private BookSearchAdapter adapter; private Handler mHandler; private ListView listView; private View v ; private Context context; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { context= getActivity(); v = inflater.inflate(R.layout.booksearch, container, false); return inflater.inflate(R.layout.booksearch, container, false); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mHandler = new Handler(); new Thread(new Runnable() { @Override public void run() { service = new BookSearchService(); list = service.queryBookList("", ""); if (list == null) result = ApplConst.FAILURE; else result = ApplConst.SUCCESS; adapter = new BookSearchAdapter(list,context); mHandler.post(new Runnable() { @Override public void run() { // TODO Auto-generated method stub listView = ((ListView) v.findViewById(R.id.books_list_view)); listView.setAdapter(adapter); listView.setDividerHeight(1); // 不显示分割线 listView.setCacheColorHint(Color.TRANSPARENT); //防止listview背景变黑 listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent newActivity = new Intent(view.getContext(), BookSearchActivity.class); Books book = (Books) listView.getItemAtPosition(position); newActivity.putExtra("BookId", book.getId()); newActivity.putExtra("categoryId", book.getCategoryId()); startActivity(newActivity); } }); } }); } }).start(); } } /////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// Adapter public class BookSearchAdapter extends BaseAdapter { private int resourceId; private List<Books> booksList; private Map<Integer, View> rowViews = new HashMap<Integer, View>(); private Context context = null; public BookSearchAdapter(List<Books> objects, Context context) { booksList = objects; this.context = context; } @Override public View getView(int position, View convertView, ViewGroup parent) { View rowView = rowViews.get(position); if (rowView == null) { SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss"); LayoutInflater layoutInflater = LayoutInflater.from(context); rowView = layoutInflater.inflate(R.layout.booksearch_items, null); TextView publicationDate = (TextView) rowView .findViewById(R.id.dtPublicationDate); TextView bookName = (TextView) rowView .findViewById(R.id.txtBookName); TextView publish = (TextView) rowView .findViewById(R.id.TxtPublish); TextView writor = (TextView) rowView .findViewById(R.id.txtWritor); Books books = booksList.get(position); if (books.publicationDate != null) publicationDate.setText("出版时间:" + DateUtil.parseDateToString( books.getPublicationDate(), df)); if(books.getBookName()!=null) bookName.setText(books.getBookName()); if(books.getWritor()!=null) writor.setText("编者:"+books.getWritor()); if(books.getBookName()!=null) publish.setText("出版社:"+books.getPublish()); rowViews.put(position, rowView); } return rowView; }

Handler中处理了Json解析并更新了ListView,如何优化Item点击

class MediaHandler extends Handler { public Map<Integer, Integer> delstr; @Override public void handleMessage(Message message) { switch (message.what) { case 1: try { dataList = new ArrayList<Map<String, String>>(); fileString = message.obj.toString(); JSONObject object = JSONObject.fromObject(fileString); JSONArray jArray = object.getJSONArray("userFiles"); for (int i = 0; i < jArray.size(); i++) { Map<String, String> map = new HashMap<String, String>(); JSONObject jObject = jArray.getJSONObject(i); map.put("fileName", jObject.get("fileName").toString()); map.put("zt", jObject.get("zt").toString()); map.put("name2", jObject.get("name2").toString()); dataList.add(map); } final MyAdapter adapter = new MyAdapter( MediaFileActivity.this, dataList); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { // TODO 自动生成的方法存根 ViewHolder holder = (ViewHolder) arg1.getTag(); holder.mtvcb.toggle();// 在每次获取点击的item时改变checkbox的状态 MyAdapter.isselected.put(position, holder.mtvcb.isChecked()); // 同时修改map的值保存状态 } }); cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean arg1) { // TODO 自动生成的方法存根 try { if (arg1) { for (int i = 0; i < dataList.size(); i++) { adapter.isselected.put(i, true); } Toast.makeText(MediaFileActivity.this, "选中了" + adapter.isselected.size(), 2).show(); adapter.notifyDataSetChanged();// 注意这一句必须加上,否则checkbox无法正常更新状态 } else { for (int i = 0; i < dataList.size(); i++) { adapter.isselected.put(i, false); } adapter.notifyDataSetChanged();// 注意这一句必须加上,否则checkbox无法正常更新状态 } } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } }); btndelete.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO 自动生成的方法存根 } }); } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } break; case 2: break; } } } 这是我Handler的一段代码,现在点击事件也再里面导致每一次点击都执行一边handler里面的所有步骤,导致有点卡,尤其是cb(checkbox)的全选点击事件,会卡几秒钟,哪位大神帮忙给个思路!

android popupwindow dismiss()关闭窗体前的处理事件

pop.setTouchable(true); pop.setBackgroundDrawable(new BitmapDrawable()); // 上面两句代码当点击窗体外部popupwindow自动消失 我想让popupwindow消失前执行一段代码,比如改变字体等,那么如何重写dismiss()方法啊? 贴出部分源码 public void popup() {// inflater = (LayoutInflater)popupTest.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View listLayout = inflater.inflate(R.layout.listview, null); listView= (ListView) listLayout.findViewById(android.R.id.list); lvButtonAdapter listItemAdapter = new lvButtonAdapter(this,list1, R.layout.item, new String[]{"text1","text2","ItemImage,RelativeLayout"}, new int[]{R.id.text1,R.id.text2,R.id.pup,R.id.re}); listView.setAdapter(listItemAdapter); listView.setFocusable(true); listView.setItemsCanFocus(true); listView.setOnItemClickListener(new OnItemClickListener(){public void onItemClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) { edit1.getText().insert (edit1.getSelectionStart(),list1.get(arg2).get("text1").toString()); pop.dismiss(); }});//光标处插入文字 pop = new PopupWindow(listLayout, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); pop.setTouchable(true); pop.setBackgroundDrawable(new BitmapDrawable()); // pop.setFocusable(true); }

按钮按了有反应,可onItemClick却没执行到

![图片说明](https://img-ask.csdn.net/upload/201705/10/1494389301_214240.png) ![图片说明](https://img-ask.csdn.net/upload/201705/10/1494389320_136211.jpg) 1.按钮按了有反应,可onItemClick却没执行到 2.无论按哪个按钮,都显示"你点击的标题是:苹果" ``` package com.example.exer; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.AlertDialog; import android.app.ListActivity; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends ListActivity { private static final String TAG = "MainActivity"; private List<Map<String, Object>> mdata; private int positio; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main); ListView mListView=getListView(); mdata = data(); mListView.setAdapter(new MyAdapter(this,mdata)); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> l, View v, int position, long id) { Log.i(TAG, (String)mdata.get(position).get("title")); Toast.makeText(MainActivity.this, (String)mdata.get(position).get("title"), 1000).show(); } }); } class MyAdapter extends BaseAdapter{ private Context context; private LayoutInflater minflater; private ArrayList<Map<String,Object>> datalist; public MyAdapter(Context context,List<Map<String,Object>> datalist) { this.context=context; this.minflater = LayoutInflater.from(context); this.datalist=(ArrayList<Map<String,Object>>)datalist; } @Override public int getCount() { // TODO Auto-generated method stub return datalist.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return datalist.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub positio=position; return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { Hodler hodler =null; if(convertView == null){ hodler = new Hodler(); convertView = minflater.inflate(R.layout.mylist, null); hodler.img = (ImageView) convertView.findViewById(R.id.img); hodler.title = (TextView) convertView.findViewById(R.id.title); hodler.info = (TextView) convertView.findViewById(R.id.info); hodler.button = (Button) convertView.findViewById(R.id.button); convertView.setTag(hodler); }else{ hodler = (Hodler) convertView.getTag(); } hodler.img.setBackgroundResource((Integer) mdata.get(position).get("img")); hodler.title.setText((CharSequence) mdata.get(position).get("title")); hodler.info.setText((CharSequence) mdata.get(position).get("info")); hodler.button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showdialog(); } }); return convertView; } class Hodler { public ImageView img; public TextView title; public TextView info; public Button button; } } public void showdialog() { new AlertDialog.Builder(this).setTitle("提示信息").setMessage("你点击的标题是: " +(String)mdata.get(positio).get("title")) .setPositiveButton("确定", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "确定", 1000).show(); setResult(RESULT_OK); finish(); } }).setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).show(); } public List<Map<String, Object>> data() { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> map = new HashMap<String, Object>(); map.put("title", "苹果"); map.put("info", "apple"); map.put("img", R.drawable.ic_launcher); list.add(map); map = new HashMap<String, Object>(); map.put("title", "书"); map.put("info", "book"); map.put("img", R.drawable.ic_launcher); list.add(map); map = new HashMap<String, Object>(); map.put("title", "电脑"); map.put("info", "computer"); map.put("img", R.drawable.ic_launcher); list.add(map); map = new HashMap<String, Object>(); map.put("title", "对话"); map.put("info", "dialog"); map.put("img", R.drawable.ic_launcher); list.add(map); map = new HashMap<String, Object>(); map.put("title", "运行"); map.put("info", "run"); map.put("img", R.drawable.ic_launcher); list.add(map); return list; } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } ```

setonclicklistener事件中如何改变其他控件的属性

public View getView(int arg0, View arg1, ViewGroup arg2) { if(arg1==null){ arg1=layoutInflater.inflate(R.layout.items, null); } ImageView musicflag = (ImageView) arg1.findViewById(R.id.musicflag); TextView musicname=(TextView) arg1.findViewById(R.id.musicname); TextView musicsinger=(TextView) arg1.findViewById(R.id.musicsingers); final ImageView musicplay = (ImageView) arg1.findViewById(R.id.musicatt); musicflag.setImageResource(R.drawable.music); musicname.setText(musics[arg0]); musicsinger.setText(musicsingers[arg0]); musicplay.setImageResource(R.drawable.play); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { //Toast.makeText(MainActivity.this, arg2+"", Toast.LENGTH_SHORT).show(); /*if (flag==0) { musicplay.setImageResource(R.drawable.pause); flag=1; }else if (flag==1) { musicplay.setImageResource(R.drawable.play); flag=0; }*/ **musicplay.setImageResource(R.drawable.pause);_** Toast.makeText(MainActivity.this, flag+"", Toast.LENGTH_SHORT).show(); Intent intent = new Intent("MusicPlay"); Bundle bundle = new Bundle(); bundle.putInt("song", arg2); intent.putExtra("int", bundle); sendBroadcast(intent); } }); ``` ``` 为什么musicplay.setImageResource(R.drawable.pause);这句话不能执行,图片没有更改

调用外部API不成功,显示的什么执行时间长,我实在解决不了了

下面是我的util package textview.exam; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; /** * Created by fei on 2016/6/16. */ public class Shishinews { String httpUrl = "http://apis.baidu.com/songshuxiansheng/news/news"; String httpArg = ""; String jsonResult = request(httpUrl, httpArg); //System.out.println(jsonResult); /** * @param urlAll * :请求接口 * @param httpArg * :参数 * @return 返回结果 */ public static String request(String httpUrl, String httpArg) { BufferedReader reader = null; String result = null; StringBuffer sbf = new StringBuffer(); httpUrl = httpUrl + "?" + httpArg; try { URL url = new URL(httpUrl); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setRequestMethod("GET"); // 填入apikey到HTTP header connection.setRequestProperty("apikey", "f761aa7e1d7b5ebe4******"); connection.connect(); InputStream is = connection.getInputStream(); reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); String strRead = null; while ((strRead = reader.readLine()) != null) { sbf.append(strRead); sbf.append("\r\n"); } reader.close(); result = sbf.toString(); } catch (Exception e) { e.printStackTrace(); } return result; } } 下面是我fragment的代码 package textview.exam; import android.annotation.SuppressLint; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class FragmentMainchatnews extends Fragment { String httpUrl = "http://apis.baidu.com/songshuxiansheng/news/news"; String httpArg = ""; private String[] title;//新闻标题 private String[] abs;//新闻简介 private String[] image_url;//图片链接地址 Thread thread = null; String newsjson; @Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.main_chat_news, null); return view; } // 开启线程得到答案 Runnable runnable = new Runnable() { @Override public void run() { newsjson = Shishinews.request(httpUrl, httpArg); Log.v("debug",newsjson); Message message = new Message(); message.what = 1;// 标志是哪个线程传数据 } }; @SuppressLint("HandlerLeak") class MyHandler extends Handler { // 接受message的信息 @Override public void handleMessage(Message msg) { super.handleMessage(msg); try { JSONObject object = new JSONObject(newsjson); newsjson = object.get("retDate").toString(); } catch (JSONException e) { e.printStackTrace(); } if (msg.what == 1) { // 创建一个List集合,List集合的元素是Map List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>(); for (int i = 0; i < title.length; i++) { Map<String, Object> listItem = new HashMap<String, Object>(); listItem.put("image", image_url[i]); listItem.put("title", title[i]); listItem.put("abs", abs[i]); listItems.add(listItem); } // 创建一个SimpleAdapter SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), listItems,R.layout.simple_item, new String[]{"image", "title", "abs"}, new int[]{R.id.image, R.id.title ,R.id.abs}); ListView list = (ListView) getView().findViewById(R.id.chat_news); // 为ListView设置Adapter list.setAdapter(simpleAdapter); // 为ListView的列表项的单击事件绑定事件监听器 list.setOnItemClickListener(new AdapterView.OnItemClickListener() { // 第position项被单击时激发该方法 @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent=new Intent(getActivity(),ChatActivity.class); startActivity(intent); } }); // 为ListView的列表项的选中事件绑定事件监听器 list.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { // 第position项被选中时激发该方法 @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { System.out.println(title[position] + "被选中了"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); } } } public void sendMessage() { if (getView().findViewById(R.id.chat_news)==null) { Toast.makeText(getActivity(), "下拉刷新", Toast.LENGTH_SHORT).show(); } else { // 创建一个List集合,List集合的元素是Map List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>(); for (int i = 0; i < title.length; i++) { Map<String, Object> listItem = new HashMap<String, Object>(); listItem.put("image", image_url[i]); listItem.put("title", title[i]); listItem.put("abs", abs[i]); listItems.add(listItem); } thread = new Thread(runnable); thread.start(); } } } 下面是我AndroidMainfest.xml中的代码 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="textview.exam" > <!-- 添加权限 --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.READ_PROFILE" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".LoginActivity" android:label="@string/title_activity_login" android:windowSoftInputMode="adjustResize|stateHidden" > </activity> <activity android:name=".ChatActivity" android:label="@string/title_activity_chat" > android:labl="聊天" </activity> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> </application> </manifest> 该有的权限我应该都设置了,可是还是不成功,大神们啊,这个我是解决不了了,就想获取个简单的新闻,我连什么关键词都没有

Fragment调用另一个Fragment replace hide 方法无效??求解决。。

selectorListFragment = new SelectorListFragment(); wiredNetWorkFragment = new WiredNetWorkFragment(); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { FragmentManager fragmentManager = getActivity().getFragmentManager(); @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { FragmentTransaction ft_info_list = fragmentManager.beginTransaction(); ft_info_list.replace(R.id.network_set_content, wifiInfoFragment); ft_info_list.addToBackStack(null); ft_info_list.commit(); FragmentTransaction fragmentTransaction_right = fragmentManager.beginTransaction(); fragmentTransaction_right.hide(WifiListFragment.this).commit(); FragmentTransaction ft_select_list = fragmentManager.beginTransaction(); ft_select_list.hide(selectorListFragment); ft_select_list.commit(); } }); ``` ``` 这里的selectorListFragment并没有被隐藏。。。

什么错误会使应用程序崩溃呢?

当我点击应用程序的logo,闪屏后,就会从intent中调用的第一个类。但是当tab加载后, onPreExecute() 一旦执行,应用程序就奔溃了。 public class HomeActivity extends Activity{ private static final String dialog = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.user_main_tab_home); new HomeDownloadPage().execute(); } public class HomeDownloadPage extends AsyncTask<String,Void,String>{ private final ProgressDialog dialog = new ProgressDialog(HomeActivity.this); protected void onPreExecute() { this.dialog.setMessage("Have Paitence! "); this.dialog.show(); } @Override protected String doInBackground(String... params) { User user = null; try { user = new User("4eeb"); user.getList(); /* * Custom adapter * */ ArrayList<User> users = new ArrayList<User>(); for(User u : user.following){ users.add(u); } ListView lv = (ListView) findViewById(R.id.user_list); final UserFollowingListAdapter csl = new UserFollowingListAdapter(HomeActivity.this,R.layout.user_list,users,this); OnItemClickListener listener = new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position,long id) { Object o = csl.getItem(position); setTitle(parent.getItemAtPosition(position).toString()); } }; lv.setAdapter(csl); lv.setOnItemClickListener(listener); /* * Onclick listener * */ lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view,int position, long id) { Intent i = new Intent("com.list.SEARCH"); Toast.makeText(HomeActivity.this, "rowitem clicked", Toast.LENGTH_LONG).show(); // TODO Auto-generated method stub } }); } catch (Exception e) { showError(); } return null; } protected void onPostExecute(String result) { // execution of result of Long time consuming operation } } public void showError(){ new AlertDialog.Builder(HomeActivity.this) .setTitle(" Oops , Server down :( ") .setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub } // }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); } } 在 doInBackground() 函数处得到错误。 确切的错误: 01-27 19:03:01.264: E/AndroidRuntime(1138): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 问题出在哪呢?

ArrayAdapter报出NullPointerException异常

在Activity中有一个listview。listview中使用arrayAdapter布局填充。array Adapter是从Activity中调用的。Activity传递一个arrayList对象到adapter。当执行Activity获得空指针异常。使用的以下的代码,要改哪里啊? 谢谢大家的指导! public class OpenTicketList extends Activity implements OnItemClickListener{ private Bundle basket; private AdapterTicketList adapterTicketList; private List<Ticket> openTicketList; private ListView listView; @TargetApi(9) public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); Log.i("OpenTicket","on create"); setContentView(R.layout.openticketlist); catchBasket(); initialize(); } private void initialize() { listView=(ListView)findViewById(R.id.lvOpenTicketList); POJO_Ticket pojo_Ticket; ArrayList<POJO_Ticket> ticketArray; ticketArray = new ArrayList<POJO_Ticket>(); for(int i=0;i<openTicketList.size();i++){ pojo_Ticket = new POJO_Ticket(openTicketList.get(i)); ticketArray.add(pojo_Ticket); Log.i("OpenTicket","i = " + Integer.toString(i)); } adapterTicketList=new AdapterTicketList(this, ticketArray); listView.setAdapter(adapterTicketList); listView.setOnItemClickListener(this); } private void catchBasket() { // TODO Auto-generated method stub basket = getIntent().getExtras(); openTicketList = (List<Ticket>) basket.getSerializable("ticket"); } } public class AdapterTicketList extends ArrayAdapter<POJO_Ticket> { Context context; ArrayList<POJO_Ticket> ticketArray; LayoutInflater vi; public AdapterTicketList(Context context , ArrayList<POJO_Ticket> ticketArray) { super(context, 0, ticketArray ); this.ticketArray = new ArrayList<POJO_Ticket>(); this.ticketArray.addAll(ticketArray); this.context =context; Log.i("AdapterTicketList"," ticket id : " + ticketArray.get(0).getTicketObject().getId()); vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } private class ViewHolder { TextView tvTicketID; TextView tvCreationHour; TextView tvTableNumber; TextView tvAmount; } public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = vi.inflate(R.layout.rowticket, null); holder.tvTicketID = (TextView) convertView.findViewById(R.id.tvTicketID); holder.tvCreationHour = (TextView) convertView.findViewById(R.id.tvCreationHour); holder.tvTableNumber = (TextView) convertView.findViewById(R.id.tvTableNumber); holder.tvAmount = (TextView) convertView.findViewById(R.id.tvQuantity); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } 相关异常: 01-08 23:01:55.287: E/AndroidRuntime(7791): FATAL EXCEPTION: main 01-08 23:01:55.287: E/AndroidRuntime(7791): android.content.res.Resources: String resource ID #0x11 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.content.res.Resources.getText(Resources.java:247) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.TextView.setText(TextView.java:3495) 01-08 23:01:55.287: E/AndroidRuntime(7791): at com.example.restaurent.AdapterTicketList.getView(AdapterTicketList.java:52) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.AbsListView.obtainView(AbsListView.java:2040) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.ListView.makeAndAddView(ListView.java:1772) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.ListView.fillDown(ListView.java:672) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.ListView.fillFromTop(ListView.java:732) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.ListView.layoutChildren(ListView.java:1625) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.AbsListView.onLayout(AbsListView.java:1870) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.View.layout(View.java:11418) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.ViewGroup.layout(ViewGroup.java:4328) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1652) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1641) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.LinearLayout.onLayout(LinearLayout.java:1417) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.View.layout(View.java:11418) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.ViewGroup.layout(ViewGroup.java:4328) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1652) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1510) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.LinearLayout.onLayout(LinearLayout.java:1415) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.View.layout(View.java:11418) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.ViewGroup.layout(ViewGroup.java:4328) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.FrameLayout.onLayout(FrameLayout.java:443) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.View.layout(View.java:11418) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.ViewGroup.layout(ViewGroup.java:4328) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1652) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1510) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.LinearLayout.onLayout(LinearLayout.java:1415) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.View.layout(View.java:11418) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.ViewGroup.layout(ViewGroup.java:4328) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.widget.FrameLayout.onLayout(FrameLayout.java:443) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.View.layout(View.java:11418) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.ViewGroup.layout(ViewGroup.java:4328) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.os.Handler.dispatchMessage(Handler.java:99) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.os.Looper.loop(Looper.java:137) 01-08 23:01:55.287: E/AndroidRuntime(7791): at android.app.ActivityThread.main(ActivityThread.java:4441) 01-08 23:01:55.287: E/AndroidRuntime(7791): at java.lang.reflect.Method.invokeNative(Native Method) 01-08 23:01:55.287: E/AndroidRuntime(7791): at java.lang.reflect.Method.invoke(Method.java:511) 01-08 23:01:55.287: E/AndroidRuntime(7791): at com.android.internal.os.ZygoteInit.run(ZygoteInit.java:784) 01-08 23:01:55.287: E/AndroidRuntime(7791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 01-08 23:01:55.287: E/AndroidRuntime(7791): at dalvik.system.NativeStart.main(Native Method)

android开发,在后台里面有数据,但Adapter没有接收到数据,找不到原因,帮忙看一下!!!

activity文件如下: //任务列表显示 listView = (ListView)findViewById(R.id.agv_rw); adapter = new AGV任务Adapter(this,dataList); listView.setAdapter(adapter); new 查询Task().execute();//查询任务 //任务列表选中一行数据 执行操作 listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //点击执行 任务编号 = adapter.getItem(position).get任务编号(); if(!任务编号.equals("")){ //隐藏 ScrollView.setVisibility(View.GONE); //显示 rlrenwu.setVisibility(View.VISIBLE); } } }); class 查询Task extends AsyncTask<Void, Void, Result<List<物流任务表>>>{ @Override protected Result<List<物流任务表>> doInBackground(Void... voids) { Result<List<物流任务表>> res = new Result<>(); 物流任务表 wl = new 物流任务表(); String param = App.gson.toJson(wl); String result = HttpUtil.sendPost(PathUtil.查询任务, param); res = TaskUtil.handle(res, result, new TypeToken<Result<List<物流任务表>>>() { }.getType()); return res; } //事后执行 @Override protected void onPostExecute(Result<List<物流任务表>> res) { if(res.isFlag()){ adapter.setDatalist(res.getData()); adapter.notifyDataSetChanged(); } } } Adapter文件如下: public class AGV任务Adapter extends BaseAdapter { private Context context; private List<物流任务表> datalist; public AGV任务Adapter(Context context, List<物流任务表> datalist) { this.context = context; this.datalist = datalist; } public void setDatalist(List<物流任务表> datalist) { this.datalist = datalist; } @Override public int getCount() { return datalist.size(); } @Override public 物流任务表 getItem(int position) { return datalist.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View view, ViewGroup parent) { if(view == null){ view = LayoutInflater.from(context).inflate(R.layout.list_agvexception_item,null); } boolean ifdraw = true; ViewHolder viewHolder = null; if(view.getTag() != null && view.getTag() instanceof ViewHolder){ viewHolder = (ViewHolder)view.getTag(); } if(ifdraw){ viewHolder = new ViewHolder(); viewHolder.物流任务表 = datalist.get(position); viewHolder.tv任务编号 = (TextView)view.findViewById(R.id.rwbh); viewHolder.tvAGV编号 = (TextView)view.findViewById(R.id.agvbh); viewHolder.tv任务状态 = (TextView)view.findViewById(R.id.rwzt); viewHolder.tv任务类型 = (TextView)view.findViewById(R.id.rwlx); viewHolder.tv任务优先级 = (TextView)view.findViewById(R.id.rwyxj); viewHolder.tv起始站点 = (TextView)view.findViewById(R.id.qszd); viewHolder.tv目的站点 = (TextView)view.findViewById(R.id.mdzd); viewHolder.tv任务编号.setText(viewHolder.物流任务表.get任务编号()); viewHolder.tvAGV编号.setText(viewHolder.物流任务表.getAGV编号()); if(viewHolder.物流任务表.get任务状态().equals("0")){ viewHolder.tv任务状态.setText("未执行"); }else if(viewHolder.物流任务表.get任务状态().equals("1")){ viewHolder.tv任务状态.setText("执行中"); }else if(viewHolder.物流任务表.get任务状态().equals("2")){ viewHolder.tv任务状态.setText("已完成"); }else if(viewHolder.物流任务表.get任务状态().equals("3")){ viewHolder.tv任务状态.setText("强制取消"); }else if(viewHolder.物流任务表.get任务状态().equals("4")){ viewHolder.tv任务状态.setText("强制完成"); }else if(viewHolder.物流任务表.get任务状态().equals("5")){ viewHolder.tv任务状态.setText("任务已获取"); }else if(viewHolder.物流任务表.get任务状态().equals("6")){ viewHolder.tv任务状态.setText("任务中止"); }else if(viewHolder.物流任务表.get任务状态().equals("9")){ viewHolder.tv任务状态.setText("任务解析错误"); } if(viewHolder.物流任务表.get任务类型().equals("I")){ viewHolder.tv任务类型.setText("生产入库"); }else if(viewHolder.物流任务表.get任务类型().equals("O")){ viewHolder.tv任务类型.setText("物料出库"); }else if(viewHolder.物流任务表.get任务类型().equals("M")){ viewHolder.tv任务类型.setText("生产上料"); }else if(viewHolder.物流任务表.get任务类型().equals("T")){ viewHolder.tv任务类型.setText("物料入库"); }else if(viewHolder.物流任务表.get任务类型().equals("R")){ viewHolder.tv任务类型.setText("木制托盘回收"); }else if(viewHolder.物流任务表.get任务类型().equals("S")){ viewHolder.tv任务类型.setText("成品托盘运送"); }else if(viewHolder.物流任务表.get任务类型().equals("E")){ viewHolder.tv任务类型.setText("调拨"); }else if(viewHolder.物流任务表.get任务类型().equals("F")){ viewHolder.tv任务类型.setText("塑料托盘回收"); }else if(viewHolder.物流任务表.get任务类型().equals("G")){ viewHolder.tv任务类型.setText("塑料托盘循环"); } if(viewHolder.物流任务表.get任务优先级().equals("S")){ viewHolder.tv任务优先级.setText("1"); }else if(viewHolder.物流任务表.get任务优先级().equals("P")){ viewHolder.tv任务优先级.setText("2"); }else if(viewHolder.物流任务表.get任务优先级().equals("I")){ viewHolder.tv任务优先级.setText("3"); }else if(viewHolder.物流任务表.get任务优先级().equals("O")){ viewHolder.tv任务优先级.setText("4"); } viewHolder.tv起始站点.setText(viewHolder.物流任务表.get起始站点()); viewHolder.tv目的站点.setText(viewHolder.物流任务表.get目的站点()); } return view; } class ViewHolder{ 物流任务表 物流任务表; TextView tv任务编号,tvAGV编号,tv任务状态,tv任务类型,tv任务优先级,tv起始站点,tv目的站点; } } 其他数据都显示唯独AGV编号这个不显示,DEBUG一下发现没有接收到数据,是NULL,但是其他都有数据,后台WEBserver中也用测试类测试了,可以查到数据,没有报错日志很奇怪,麻烦大家帮忙看看是什么原因造成的。

java.lang.IllegalStateException:

03-23 15:07:45.899: E/AndroidRuntime(12482): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. public class AppManagerActivity extends Activity implements OnClickListener { private List<AppInfo> mAppInfoList; private ListView lv_app_list; private MyAdapter mAdapter; private ArrayList<AppInfo> mSystemList; private ArrayList<AppInfo> mCustomerList; private TextView tv_des; private AppInfo mAppInfo; private Handler mHandler =new Handler(){ public void handleMessage(android.os.Message msg){ mAdapter = new MyAdapter(); lv_app_list.setAdapter(mAdapter); if (tv_des!=null&&mCustomerList!=null) { tv_des.setText("用户应用("+mCustomerList.size()+")"); } }; }; class MyAdapter extends BaseAdapter{ //获取适配器中条目类型的总数(改成两种,纯文字,文件+图片) @Override public int getViewTypeCount(){ return super.getViewTypeCount()+1; } //指定索引指向条目的类型,条目类型状态码指定(0(复用),1) @Override public int getItemViewType(int position){ if (position==0||position==mCustomerList.size()+1) { //返回0,代表纯文本条目的状态码 return 0; } else { //返回1,代表文本+图片条目的状态码 return 1; } } @Override public int getCount() { //listView中增加两个描述项目 return mSystemList.size()+mCustomerList.size()+2; } @Override public AppInfo getItem(int position) { if (position==0||position==mCustomerList.size()+1) { return null; }else { if (position<mCustomerList.size()+1) { return mCustomerList.get(position-1); }else { //返回应用对应条目的对象 return mSystemList.get(position-mCustomerList.size()-2); } } } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { int type = getItemViewType(position); if (type==0) { //展示纯文本灰色条目 ViewTitleHolder holder=null; if (convertView==null) { convertView=View.inflate(getApplicationContext(),R.layout.listview_app_item_title,null); holder=new ViewTitleHolder(); holder.tv_title=(TextView)convertView.findViewById(R.id.tv_title); convertView.setTag(holder); }else { holder=(ViewTitleHolder)convertView.getTag(); } if (position==0) { holder.tv_title.setText("用户应用("+mCustomerList.size()+")"); }else { holder.tv_title.setText("系统应用("+mSystemList.size()+")"); } return convertView; }else { //展示文本加图片条目 ViewHolder holder=null; if (convertView==null) { convertView=View.inflate(getApplicationContext(),R.layout.listview_app_item,null); holder=new ViewHolder(); holder.iv_icon=(ImageView)convertView.findViewById(R.id.iv_icon); holder.tv_name=(TextView)convertView.findViewById(R.id.tv_name); holder.tv_path=(TextView)convertView.findViewById(R.id.tv_path); convertView.setTag(holder); }else { holder=(ViewHolder)convertView.getTag(); } holder.iv_icon.setBackgroundDrawable(getItem(position).icon); holder.tv_name.setText(getItem(position).name); if (getItem(position).isSdCard) { holder.tv_path.setText("sd卡应用"); }else { holder.tv_path.setText("手机应用"); } return convertView; } } } static class ViewHolder{ ImageView iv_icon; TextView tv_name; TextView tv_path; } static class ViewTitleHolder{ TextView tv_title; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_app_manager); initTitle(); initList(); } private void initList() { tv_des = (TextView)findViewById(R.id.tv_des); lv_app_list = (ListView)findViewById(R.id.lv_app_list); new Thread(){ public void run(){ mAppInfoList = AppInfoProvider.getAppInfoList(getApplicationContext()); mSystemList = new ArrayList<AppInfo>(); mCustomerList = new ArrayList<AppInfo>(); for (AppInfo appInfo : mAppInfoList) { if (appInfo.isSystem) { //系统应用 mSystemList.add(appInfo); }else { //非系统应用 mCustomerList.add(appInfo); } } mHandler.sendEmptyMessage(0); }; }.start(); lv_app_list.setOnScrollListener(new OnScrollListener(){ @Override public void onScrollStateChanged(AbsListView view, int scrollState) { // TODO Auto-generated method stub } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { //滚动过程中调用方法 //AbsListView中view就是listView对象 //firstVisibleItem第一个可见条目索引值 //visibleItemCount当前一个屏幕的可见条目数 //总共条目总数 if (mCustomerList!=null&&mSystemList!=null) { if (firstVisibleItem>=mCustomerList.size()+1) { //滚动到了系统应用 tv_des.setText("系统应用("+mSystemList.size()+")"); }else { //滚动到了用户条目 tv_des.setText("用户应用("+mCustomerList.size()+")"); } } } }); lv_app_list.setOnItemClickListener(new OnItemClickListener(){ //view点中条目指向view的对象 @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub if (position==0||position==mCustomerList.size()+1) { return; }else { if (position<mCustomerList.size()+1) { mAppInfo = mCustomerList.get(position-1); }else { //返回应用对应条目的对象 mAppInfo=mSystemList.get(position-mCustomerList.size()-2); } showPopupWindow(view); } } }); } protected void showPopupWindow(View view) { View popupView = View.inflate(this,R.layout.popupwindow_layout,null); TextView tv_uninstall =(TextView)popupView.findViewById(R.id.tv_uninstall); TextView tv_start=(TextView)popupView.findViewById(R.id.tv_start); TextView tv_share=(TextView)popupView.findViewById(R.id.tv_share); tv_uninstall.setOnClickListener(this); tv_start.setOnClickListener(this); tv_share.setOnClickListener(this); //1,创建窗体对象,指定宽高 PopupWindow popupWindow = new PopupWindow(view, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT,true); //2,设置一个透明背景,如果不设置,回退按钮没反应 popupWindow.setBackgroundDrawable(new ColorDrawable()); //3,指定窗体位置 popupWindow.showAsDropDown(view,50,-view.getHeight()); } /** * */ private void initTitle() { //1,获取磁盘(区分于运存)可用大小,磁盘路径 String path = Environment.getDataDirectory().getAbsolutePath(); //2,获取sd卡可用大小,sd卡路径 String sdPath = Environment.getExternalStorageDirectory().getAbsolutePath(); //3,获取以上两个路径下文件夹的可用大小 String memoryAvailSpace= Formatter.formatFileSize(this,getAvailSpace(path)); String sdMemoryAvailSpace = Formatter.formatFileSize(this,getAvailSpace(sdPath)); TextView tv_memory = (TextView) findViewById(R.id.tv_memory); TextView tv_sd_memory = (TextView) findViewById(R.id.tv_sd_memory); tv_memory.setText("磁盘可用:"+memoryAvailSpace); tv_sd_memory.setText("sd卡可用:"+sdMemoryAvailSpace); } private long getAvailSpace(String path) { //statFs获取可用磁盘大小的一个类 StatFs statFs = new StatFs(path); //获取可用区块的个数 long count = statFs.getAvailableBlocks(); //获取区块的大小 long size = statFs.getBlockSize(); //区块大小*可用区块个数=可用空间大小 return count*size; } @Override public void onClick(View v) { // TODO Auto-generated method stub } }

运行到setContentView这里崩溃了

这是第一行代码里面的一个项目,运行后崩溃: ![图片说明](https://img-ask.csdn.net/upload/201702/12/1486848687_748230.jpg) MainActivity.java ``` package com.example.newsapp; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.Window; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } ``` News.java ``` package com.example.newsapp; public class News { private String title; private String content; public String getTitle() { return title; } public void setTitle(String title) { this.title=title; } public String getContent() { return content; } public void setContent(String content) { this.content=content; } } ``` NewsAdapter.java ``` package com.example.newsapp; import java.util.List; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; public class NewsAdapter extends ArrayAdapter<News> { private int resourceId; public NewsAdapter(Context context,int textViewResourceId,List<News> objects) { super(context,textViewResourceId,objects); resourceId=textViewResourceId; } @Override public View getView(int position,View convertView,ViewGroup parent) { News news=getItem(position); View view; if (convertView==null) { view=LayoutInflater.from(getContext()).inflate(resourceId,null); } else { view=convertView; } TextView newsTitleText=(TextView)view.findViewById(R.id.news_title); newsTitleText.setText(news.getTitle()); return view; } } ``` NewsContentActivity.java ``` package com.example.newsapp; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.view.Window; public class NewsContentActivity extends FragmentActivity { public static void actionStart(Context context,String newsTitle,String newsContent) { Intent intent=new Intent(context,NewsContentActivity.class ); intent.putExtra("news_title",newsTitle); intent.putExtra("news_content",newsContent); context.startActivity(intent); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.news_content); FragmentManager fragmentManager=getSupportFragmentManager(); String newsTitle=getIntent().getStringExtra("news_title"); String newsContent=getIntent().getStringExtra("news_content"); NewsContentFragment newsContentFragment=(NewsContentFragment)fragmentManager.findFragmentById(R.id.news_content_fragment); newsContentFragment.refresh(newsTitle,newsContent); } } ``` NewsContentFragment.java ``` package com.example.newsapp; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class NewsContentFragment extends Fragment { private View view; @Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) { view=inflater.inflate(R.layout.news_content_frag,container,false ); return view; } public void refresh(String newsTitle,String newsContent) { View visibilityLayout=view.findViewById(R.id.visibility_layout); visibilityLayout.setVisibility(View.VISIBLE); TextView newsTitleText=(TextView)view.findViewById(R.id.news_title); TextView newsContentText=(TextView)view.findViewById(R.id.news_content); newsTitleText.setText(newsTitle); newsContentText.setText(newsContent); } } ``` NewsTitleFragment.java ``` package com.example.newsapp; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; public class NewsTitleFragment extends Fragment implements OnItemClickListener { private ListView newsTitleListView; private List<News> newsList; private NewsAdapter adapter; private boolean isTwoPane; @Override public void onAttach(Activity activity) { super.onAttach(activity); newsList=getNews(); adapter=new NewsAdapter(activity,R.layout.news_item,newsList); } @Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) { View view=inflater.inflate(R.layout.news_title_frag,container,false ); newsTitleListView=(ListView)view.findViewById(R.id.news_title_list_view); newsTitleListView.setAdapter(adapter); newsTitleListView.setOnItemClickListener(this ); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (getActivity().findViewById(R.id.news_content_layout)!=null ) isTwoPane=true; else isTwoPane=false; } @Override public void onItemClick(AdapterView<?> parent,View view,int position,long id) { News news=newsList.get(position); if (isTwoPane) { NewsContentFragment newsContentFragment=(NewsContentFragment)getFragmentManager().findFragmentById(R.id.news_content_fragment); newsContentFragment.refresh(news.getTitle(),news.getContent()); } else { NewsContentActivity.actionStart(getActivity(),news.getTitle(),news.getContent()); } } private List<News> getNews() { List<News> newsList=new ArrayList<News>(); News news1=new News(); news1.setTitle("标题"); news1.setContent("内容"); newsList.add(news1); News news2=new News(); news2.setTitle("日记"); news2.setContent("去旅游"); newsList.add(news2); return newsList; } } ```

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

课程主要面向嵌入式Linux初学者、工程师、学生 主要从一下几方面进行讲解: 1.linux学习路线、基本命令、高级命令 2.shell、vi及vim入门讲解 3.软件安装下载、NFS、Samba、FTP等服务器配置及使用

我以为我对Mysql事务很熟,直到我遇到了阿里面试官

太惨了,面试又被吊打

Python代码实现飞机大战

文章目录经典飞机大战一.游戏设定二.我方飞机三.敌方飞机四.发射子弹五.发放补给包六.主模块 经典飞机大战 源代码以及素材资料(图片,音频)可从下面的github中下载: 飞机大战源代码以及素材资料github项目地址链接 ————————————————————————————————————————————————————————— 不知道大家有没有打过飞机,喜不喜欢打飞机。当我第一次接触这个东西的时候,我的内心是被震撼到的。第一次接触打飞机的时候作者本人是身心愉悦的,因为周边的朋友都在打飞机, 每

Python数据分析与挖掘

92讲视频课+16大项目实战+源码+¥800元课程礼包+讲师社群1V1答疑+社群闭门分享会=99元 &nbsp; 为什么学习数据分析? &nbsp; &nbsp; &nbsp; 人工智能、大数据时代有什么技能是可以运用在各种行业的?数据分析就是。 &nbsp; &nbsp; &nbsp; 从海量数据中获得别人看不见的信息,创业者可以通过数据分析来优化产品,营销人员可以通过数据分析改进营销策略,产品经理可以通过数据分析洞察用户习惯,金融从业者可以通过数据分析规避投资风险,程序员可以通过数据分析进一步挖掘出数据价值,它和编程一样,本质上也是一个工具,通过数据来对现实事物进行分析和识别的能力。不管你从事什么行业,掌握了数据分析能力,往往在其岗位上更有竞争力。 &nbsp;&nbsp; 本课程共包含五大模块: 一、先导篇: 通过分析数据分析师的一天,让学员了解全面了解成为一个数据分析师的所有必修功法,对数据分析师不在迷惑。 &nbsp; 二、基础篇: 围绕Python基础语法介绍、数据预处理、数据可视化以及数据分析与挖掘......这些核心技能模块展开,帮助你快速而全面的掌握和了解成为一个数据分析师的所有必修功法。 &nbsp; 三、数据采集篇: 通过网络爬虫实战解决数据分析的必经之路:数据从何来的问题,讲解常见的爬虫套路并利用三大实战帮助学员扎实数据采集能力,避免没有数据可分析的尴尬。 &nbsp; 四、分析工具篇: 讲解数据分析避不开的科学计算库Numpy、数据分析工具Pandas及常见可视化工具Matplotlib。 &nbsp; 五、算法篇: 算法是数据分析的精华,课程精选10大算法,包括分类、聚类、预测3大类型,每个算法都从原理和案例两个角度学习,让你不仅能用起来,了解原理,还能知道为什么这么做。

如何在虚拟机VM上使用串口

在系统内核开发中,经常会用到串口调试,利用VMware的Virtual Machine更是为调试系统内核如虎添翼。那么怎么搭建串口调试环境呢?因为最近工作涉及到这方面,利用强大的google搜索和自己

程序员的兼职技能课

获取讲师答疑方式: 在付费视频第一节(触摸命令_ALL)片头有二维码及加群流程介绍 限时福利 原价99元,今日仅需39元!购课添加小助手(微信号:csdn590)按提示还可领取价值800元的编程大礼包! 讲师介绍: 苏奕嘉&nbsp;前阿里UC项目工程师 脚本开发平台官方认证满级(六级)开发者。 我将如何教会你通过【定制脚本】赚到你人生的第一桶金? 零基础程序定制脚本开发课程,是完全针对零脚本开发经验的小白而设计,课程内容共分为3大阶段: ①前期将带你掌握Q开发语言和界面交互开发能力; ②中期通过实战来制作有具体需求的定制脚本; ③后期将解锁脚本的更高阶玩法,打通任督二脉; ④应用定制脚本合法赚取额外收入的完整经验分享,带你通过程序定制脚本开发这项副业,赚取到你的第一桶金!

MFC一站式终极全套课程包

该套餐共包含从C小白到C++到MFC的全部课程,整套学下来绝对成为一名C++大牛!!!

C++语言基础视频教程

C++语言基础视频培训课程:本课与主讲者在大学开出的程序设计课程直接对接,准确把握知识点,注重教学视频与实践体系的结合,帮助初学者有效学习。本教程详细介绍C++语言中的封装、数据隐藏、继承、多态的实现等入门知识;主要包括类的声明、对象定义、构造函数和析构函数、运算符重载、继承和派生、多态性实现等。 课程需要有C语言程序设计的基础(可以利用本人开出的《C语言与程序设计》系列课学习)。学习者能够通过实践的方式,学会利用C++语言解决问题,具备进一步学习利用C++开发应用程序的基础。

北京师范大学信息科学与技术学院笔试10复试真题

北京师范大学信息科学与技术学院笔试,可以更好的让你了解北师大该学院的复试内容,获得更好的成绩。

深度学习原理+项目实战+算法详解+主流框架(套餐)

深度学习系列课程从深度学习基础知识点开始讲解一步步进入神经网络的世界再到卷积和递归神经网络,详解各大经典网络架构。实战部分选择当下最火爆深度学习框架PyTorch与Tensorflow/Keras,全程实战演示框架核心使用与建模方法。项目实战部分选择计算机视觉与自然语言处理领域经典项目,从零开始详解算法原理,debug模式逐行代码解读。适合准备就业和转行的同学们加入学习! 建议按照下列课程顺序来进行学习 (1)掌握深度学习必备经典网络架构 (2)深度框架实战方法 (3)计算机视觉与自然语言处理项目实战。(按照课程排列顺序即可)

网络工程师小白入门--【思科CCNA、华为HCNA等网络工程师认证】

本课程适合CCNA或HCNA网络小白同志,高手请绕道,可以直接学习进价课程。通过本预科课程的学习,为学习网络工程师、思科CCNA、华为HCNA这些认证打下坚实的基础! 重要!思科认证2020年2月24日起,已启用新版认证和考试,包括题库都会更新,由于疫情原因,请关注官网和本地考点信息。题库网络上很容易下载到。

Python界面版学生管理系统

前不久上传了一个控制台版本的学生管理系统,这个是Python界面版学生管理系统,这个是使用pycharm开发的一个有界面的学生管理系统,基本的增删改查,里面又演示视频和完整代码,有需要的伙伴可以自行下

软件测试2小时入门

本课程内容系统、全面、简洁、通俗易懂,通过2个多小时的介绍,让大家对软件测试有个系统的理解和认识,具备基本的软件测试理论基础。 主要内容分为5个部分: 1 软件测试概述,了解测试是什么、测试的对象、原则、流程、方法、模型;&nbsp; 2.常用的黑盒测试用例设计方法及示例演示;&nbsp; 3 常用白盒测试用例设计方法及示例演示;&nbsp; 4.自动化测试优缺点、使用范围及示例‘;&nbsp; 5.测试经验谈。

Tomcat服务器下载、安装、配置环境变量教程(超详细)

未经我的允许,请不要转载我的文章,在此郑重声明!!! 请先配置安装好Java的环境,若没有安装,请参照我博客上的步骤进行安装! 安装Java环境教程https://blog.csdn.net/qq_40881680/article/details/83585542 Tomcat部署Web项目(一)·内嵌https://blog.csdn.net/qq_40881680/article/d...

2019数学建模A题高压油管的压力控制 省一论文即代码

2019数学建模A题高压油管的压力控制省一完整论文即详细C++和Matlab代码,希望对同学们有所帮助

图书管理系统(Java + Mysql)我的第一个完全自己做的实训项目

图书管理系统 Java + MySQL 完整实训代码,MVC三层架构组织,包含所有用到的图片资源以及数据库文件,大三上学期实训,注释很详细,按照阿里巴巴Java编程规范编写

linux下利用/proc进行进程树的打印

在linux下利用c语言实现的进程树的打印,主要通过/proc下的目录中的进程文件,获取status中的进程信息内容,然后利用递归实现进程树的打印

微信小程序开发实战之番茄时钟开发

微信小程序番茄时钟视频教程,本课程将带着各位学员开发一个小程序初级实战类项目,针对只看过官方文档而又无从下手的开发者来说,可以作为一个较好的练手项目,对于有小程序开发经验的开发者而言,可以更好加深对小程序各类组件和API 的理解,为更深层次高难度的项目做铺垫。

[已解决]踩过的坑之mysql连接报“Communications link failure”错误

目录 前言 第一种方法: 第二种方法 第三种方法(适用于项目和数据库在同一台服务器) 第四种方法 第五种方法(项目和数据库不在同一台服务器) 总结 前言 先给大家简述一下我的坑吧,(我用的是mysql,至于oracle有没有这样的问题,有心的小伙伴们可以测试一下哈), 在自己做个javaweb测试项目的时候,因为买的是云服务器,所以数据库连接的是用ip地址,用IDE开发好...

人工智能-计算机视觉实战之路(必备算法+深度学习+项目实战)

系列课程主要分为3大阶段:(1)首先掌握计算机视觉必备算法原理,结合Opencv进行学习与练手,通过实际视项目进行案例应用展示。(2)进军当下最火的深度学习进行视觉任务实战,掌握深度学习中必备算法原理与网络模型架构。(3)结合经典深度学习框架与实战项目进行实战,基于真实数据集展开业务分析与建模实战。整体风格通俗易懂,项目驱动学习与就业面试。 建议同学们按照下列顺序来进行学习:1.Python入门视频课程 2.Opencv计算机视觉实战(Python版) 3.深度学习框架-PyTorch实战/人工智能框架实战精讲:Keras项目 4.Python-深度学习-物体检测实战 5.后续实战课程按照自己喜好选择就可以

2019 AI开发者大会

2019 AI开发者大会(AI ProCon 2019)是由中国IT社区CSDN主办的AI技术与产业年度盛会。多年经验淬炼,如今蓄势待发:2019年9月6-7日,大会将有近百位中美顶尖AI专家、知名企业代表以及千余名AI开发者齐聚北京,进行技术解读和产业论证。我们不空谈口号,只谈技术,诚挚邀请AI业内人士一起共铸人工智能新篇章!

机器学习初学者必会的案例精讲

通过六个实际的编码项目,带领同学入门人工智能。这些项目涉及机器学习(回归,分类,聚类),深度学习(神经网络),底层数学算法,Weka数据挖掘,利用Git开源项目实战等。

Python数据分析师-实战系列

系列课程主要包括Python数据分析必备工具包,数据分析案例实战,核心算法实战与企业级数据分析与建模解决方案实战,建议大家按照系列课程阶段顺序进行学习。所有数据集均为企业收集的真实数据集,整体风格以实战为导向,通俗讲解Python数据分析核心技巧与实战解决方案。

YOLOv3目标检测实战系列课程

《YOLOv3目标检测实战系列课程》旨在帮助大家掌握YOLOv3目标检测的训练、原理、源码与网络模型改进方法。 本课程的YOLOv3使用原作darknet(c语言编写),在Ubuntu系统上做项目演示。 本系列课程包括三门课: (1)《YOLOv3目标检测实战:训练自己的数据集》 包括:安装darknet、给自己的数据集打标签、整理自己的数据集、修改配置文件、训练自己的数据集、测试训练出的网络模型、性能统计(mAP计算和画出PR曲线)和先验框聚类。 (2)《YOLOv3目标检测:原理与源码解析》讲解YOLOv1、YOLOv2、YOLOv3的原理、程序流程并解析各层的源码。 (3)《YOLOv3目标检测:网络模型改进方法》讲解YOLOv3的改进方法,包括改进1:不显示指定类别目标的方法 (增加功能) ;改进2:合并BN层到卷积层 (加快推理速度) ; 改进3:使用GIoU指标和损失函数 (提高检测精度) ;改进4:tiny YOLOv3 (简化网络模型)并介绍 AlexeyAB/darknet项目。

2021考研数学张宇基础30讲.pdf

张宇:博士,全国著名考研数学辅导专家,教育部“国家精品课程建设骨干教师”,全国畅销书《张宇高等数学18讲》《张宇线性代数9讲》《张宇概率论与数理统计9讲》《张宇考研数学题源探析经典1000题》《张宇考

三个项目玩转深度学习(附1G源码)

从事大数据与人工智能开发与实践约十年,钱老师亲自见证了大数据行业的发展与人工智能的从冷到热。事实证明,计算机技术的发展,算力突破,海量数据,机器人技术等,开启了第四次工业革命的序章。深度学习图像分类一直是人工智能的经典任务,是智慧零售、安防、无人驾驶等机器视觉应用领域的核心技术之一,掌握图像分类技术是机器视觉学习的重中之重。针对现有线上学习的特点与实际需求,我们开发了人工智能案例实战系列课程。打造:以项目案例实践为驱动的课程学习方式,覆盖了智能零售,智慧交通等常见领域,通过基础学习、项目案例实践、社群答疑,三维立体的方式,打造最好的学习效果。

DirectX修复工具V4.0增强版

DirectX修复工具(DirectX Repair)是一款系统级工具软件,简便易用。本程序为绿色版,无需安装,可直接运行。 本程序的主要功能是检测当前系统的DirectX状态,如果发现异常则进行修复

期末考试评分标准的数学模型

大学期末考试与高中的考试存在很大的不同之处,大学的期末考试成绩是主要分为两个部分:平时成绩和期末考试成绩。平时成绩和期末考试成绩总分一般为一百分,然而平时成绩与期末考试成绩所占的比例不同会导致出现不同

Vue.js 2.0之全家桶系列视频课程

基于新的Vue.js 2.3版本, 目前新全的Vue.js教学视频,让你少走弯路,直达技术前沿! 1. 包含Vue.js全家桶(vue.js、vue-router、axios、vuex、vue-cli、webpack、ElementUI等) 2. 采用笔记+代码案例的形式讲解,通俗易懂

c语言项目开发实例

十个c语言案例 (1)贪吃蛇 (2)五子棋游戏 (3)电话薄管理系统 (4)计算器 (5)万年历 (6)电子表 (7)客户端和服务器通信 (8)潜艇大战游戏 (9)鼠标器程序 (10)手机通讯录系统

相关热词 c# 不能序列化继承类 c# char* 调用 c# 开发dll模板 c#添加控件到工具箱 c#控制台组合数 编程计算猴子吃桃问题c# c# wpf 背景透明 随机抽取号码软件c# c# 开发环境 c# 属性和字段
立即提问