for (int i = 0; i < string.length; i++) {
list.add(“想发火” + i);
}
if (list != null && list.size() > 0) {
MyAdapter adapter = new MyAdapter(MainActivity.this, list);
listView.setAdapter(adapter);
}
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Toast.makeText(MainActivity.this, “我想打死你,***”,
Toast.LENGTH_SHORT).show();
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return toggle.onOptionsItemSelected(item)||super.onOptionsItemSelected(item);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
toggle.onConfigurationChanged(newConfig);
}
}
class MyAdapter extends BaseAdapter {
private Context context;
private ArrayList list;
public MyAdapter(Context context, ArrayList list) {
this.context = context;
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
ViewHolder vHolder;
if (arg1 == null) {
arg1 = LayoutInflater.from(context).inflate(R.layout.listview_item,
null);
vHolder = new ViewHolder();
vHolder.textView = (TextView) arg1.findViewById(R.id.list_text);
arg1.setTag(vHolder);
} else {
vHolder = (ViewHolder) arg1.getTag();
}
String string = list.get(arg0);
vHolder.textView.setText(string);
return arg1;
}
class ViewHolder {
TextView textView;
}
}
下面给出相关的布局文件:
<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:id=“@+id/drawer”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical” >
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent” >
<ImageView
android:id=“@+id/img”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:src=“@drawable/ic_launcher” />
<LinearLayout
android:layout_width=“300dp”
android:layout_height=“match_parent”
android:layout_gravity=“left”
android:background=“#ff0” >
<ListView
android:id=“@+id/list”
android:layout_width=“match_parent”
android:layout_height=“match_parent” />
</android.support.v4.widget.DrawerLayout>
<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:paddingBottom=“@dimen/activity_vertical_margin”
android:paddingLeft=“@dimen/activity_horizontal_margin”
android:paddingRight=“@dimen/activity_horizontal_margin”
android:paddingTop=“@dimen/activity_vertical_margin”
tools:context=“.MainActivity”
android:background=“#ddf”>
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“match_parent”
android:layout_height=“match_parent” >
<TextView
android:id=“@+id/list_text”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
/>
从上面的布局代码可以看出,采用了布局优化之include的写法。(还有一种常用的布局优化方式是样式抽取)。
效果如下:
这个就是使用DrawerLayout实现抽屉效果的代码,比较重要的地方给出了注释,如有不理解的地方,欢迎提出问题,博主会在第一时间给您解答。
不足之处还望多多指教!
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
尾声
以薪资待遇为基础,以发展为最终目标,要在高薪资的地方,谋求最好的发展!
下面是有几位Android行业大佬对应上方技术点整理的一些进阶资料。
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
战项目、讲解视频,并且会持续更新!**
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
[外链图片转存中…(img-YzIuInsg-1713731152004)]
尾声
以薪资待遇为基础,以发展为最终目标,要在高薪资的地方,谋求最好的发展!
下面是有几位Android行业大佬对应上方技术点整理的一些进阶资料。
[外链图片转存中…(img-c9qbwp4Z-1713731152004)]
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!