I am creating a list of apps on Android, and I am trying to place a button at the bottom that is different from the list of apps.
However, when the buttons are placed, all the buttons on the list are overlapped and given.
(Buttons appear to be being handled as part of the parts listed.)
Is there a way to place the button at the bottom apart from the list?I've been thinking about it for about 3 days, so I'd appreciate it if you could help me.
(In xml, ImageView, TextView, TextView, and LinearLayout are defined in RelativeLayout, and buttons are defined in LinearLayout.
The list of apps is implemented using listView and ArrayAdapter.)
public class LancherApp extensions Activity {
//
private ArrayList<String>items=null;
//
private ApplicationListAdapter adapter = null;
@ Override
protected void onCreate (Bundle bundle) {
super.onCreate(bundle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
// create String Arraylist.
List<AppData>appList=new ArrayList<AppData>();
// create PackageManager.
PackageManager packageManager=getPackageManager();
// make application list in your device has already installed.
final List <ApplicationInfo>installedAppList=packageManager.getInstalledApplications (PackageManager.GET_META_DATA);
for (ApplicationInfo app:installedAppList) {
AppData data = new AppData();
data.label=app.loadLabel(packageManager).toString();
data.icon=app.loadIcon(packageManager);
data.name=app.packageName;
appList.add(data);
}
finalListView listView = newListView(this);
adapter = new ApplicationListAdapter(this,appList);
listView.setAdapter(adapter);
setContentView (listView);
}
// private adapter class indicators label and icon of application.
private static class ApplicationListAdapter extensions ArrayAdapter <AppData>{
//
private final LayoutInflater mInflater;
public ApplicationListAdapter (Context context, List<AppData>dataList) {
super(context, R.layout.activity_main);
mInflater= (LayoutInflater)
context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
addAll(dataList);
}
@ Override
publicView getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = new ViewHolder();
if(convertView==null){
convertView=mInflater.inflate(R.layout.activity_main, parent, false);
holder.textLabel=(TextView) convertView.findViewById(R.id.label);
holder.imageIcon=(ImageView)convertView.findViewById(R.id.icon);
holder.packageName=(TextView) convertView.findViewById(R.id.name);
convertView.setTag(holder);
} else{
holder=(ViewHolder)convertView.getTag();
}
//
final AppData data=getItem(position);
//
holder.textLabel.setText(data.label);
holder.imageIcon.setImageDrawable(data.icon);
holder.packageName.setText(data.name);
return convertView;
}
}
// private class for storage application data.
private static class AppData{
String label;
Drawable icon;
String name;
}
// private class ViewHolder.
private static class ViewHolder {
TextView textLabel;
ImageView imageIcon;
TextView packageName;
}
<?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"
android: orientation="vertical">
<ImageView
android: id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1"/>
<TextView
android: id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/icon"
android:textSize="18sp"
android:layout_weight="1"/>
<TextView
android: id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/label"
android:layout_alignParentRight="true"
android:layout_below="@+id/label"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android: orientation="vertical">
<Button
android: id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_weight="1"
android:text="Button"/>
</LinearLayout>
</RelativeLayout>
Write the layout of one element of ListView and the layout of the entire screen in separate XML files.
For example, as an image,
The layout of one element of ListView is
<RelativeLayout>
<ImageView/>
<TextView/>
<TextView/>
</RelativeLayout>
The entire screen layout is
<LinearLayout>
<ListView/>
<Button/>
</LinearLayout>
as shown in
For Java code,
Specify each .
You don't need to create ListView in new ListView(this)
because it's the layout of the entire screen. Obtain it in findViewById()
.
As a result, I think it will be as follows. (Please note that we have not even tried compiling.)
Java code:LancerApp.java:
public class LancherApp extensions Activity {
//
private ArrayList<String>items=null;
//
private ApplicationListAdapter adapter = null;
@ Override
protected void onCreate (Bundle bundle) {
super.onCreate(bundle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
// create String Arraylist.
List<AppData>appList=new ArrayList<AppData>();
// create PackageManager.
PackageManager packageManager=getPackageManager();
// make application list in your device has already installed.
final List <ApplicationInfo>installedAppList=packageManager.getInstalledApplications (PackageManager.GET_META_DATA);
for (ApplicationInfo app:installedAppList) {
AppData data = new AppData();
data.label=app.loadLabel(packageManager).toString();
data.icon=app.loadIcon(packageManager);
data.name=app.packageName;
appList.add(data);
}
finalListView listView=(ListView) findViewById (R.id.list);
adapter = new ApplicationListAdapter(this,appList);
listView.setAdapter(adapter);
}
// private adapter class indicators label and icon of application.
private static class ApplicationListAdapter extensions ArrayAdapter <AppData>{
//
private final LayoutInflater mInflater;
public ApplicationListAdapter (Context context, List<AppData>dataList) {
super(context,R.layout.list_item);
mInflater= (LayoutInflater)
context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
addAll(dataList);
}
@ Override
publicView getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = new ViewHolder();
if(convertView==null){
convertView=mInflater.inflate(R.layout.list_item, parent, false);
holder.textLabel=(TextView) convertView.findViewById(R.id.label);
holder.imageIcon=(ImageView)convertView.findViewById(R.id.icon);
holder.packageName=(TextView) convertView.findViewById(R.id.name);
convertView.setTag(holder);
} else{
holder=(ViewHolder)convertView.getTag();
}
//
final AppData data=getItem(position);
//
holder.textLabel.setText(data.label);
holder.imageIcon.setImageDrawable(data.icon);
holder.packageName.setText(data.name);
return convertView;
}
}
// private class for storage application data.
private static class AppData{
String label;
Drawable icon;
String name;
}
// private class ViewHolder.
private static class ViewHolder {
TextView textLabel;
ImageView imageIcon;
TextView packageName;
}
}
Full screen layout:activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android: orientation="vertical">
<ListView
android: id="@+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android: id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"/>
</LinearLayout>
Single Element Layout: list_item.xml:
<?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"
android: orientation="vertical">
<ImageView
android: id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1"/>
<TextView
android: id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/icon"
android:textSize="18sp"
android:layout_weight="1"/>
<TextView
android: id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/label"
android:layout_alignParentRight="true"
android:layout_below="@+id/label"
android:layout_weight="1"/>
</RelativeLayout>
© 2024 OneMinuteCode. All rights reserved.