Reputation: 237
I would like to get the list of my installed application in a listview for each application there is two toggleButton the first to add and the second is to protect (as shown by the image below ). I'd like in a first time to add a button after the list a tried to use a scroll view with no result. The problem with a big list I can't find my button.
My two Layouts are given below :
<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" >
<LinearLayout
android:id="@+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal"
>
<TextView
android:id="@+id/maTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="180dip"
android:gravity="center_vertical|center_horizontal"
android:text="Ajouter Bloquer" />
</LinearLayout>
<ListView
android:id="@+id/lv_countries"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linear"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:clickable="true"
tools:context=".MainActivity" />
<LinearLayout
android:id="@+id/linear1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/lv_countries"
android:orientation="horizontal"
>
<Button
android:id="@+id/button25"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Valider" >
</Button>
</LinearLayout>
</RelativeLayout>
and :
<?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/tv_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="5dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight = "160dip">
<ToggleButton
android:id="@+id/tgl_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="false"
android:layout_marginRight="80dip" />
<ToggleButton
android:id="@+id/tgl_status1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="false" />
</LinearLayout>
</RelativeLayout>
In a second time I would like to add the icon with the name of the aplication. So I tried to change my Adapter the used one is
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.lv_layout, from, to);
I tried to creat an Adapter to use the icon of applications with their name my adapter:
ublic class AppListAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private List<App> mApps;
/** a map which maps the package name of an app to its icon drawable */
private Map<String, Drawable> mIcons;
private Drawable mStdImg;
/**
* Constructor.
*
* @param context the application context which is needed for the layout inflater
*/
public AppListAdapter(Context context, List<HashMap<String, Object>> aList, int r, String[] from, int[] to) {
// cache the LayoutInflater to avoid asking for a new one each time
mInflater = LayoutInflater.from(context);
// set the default icon until the actual icon is loaded for an app
mStdImg = context.getResources().getDrawable(R.drawable.icon);
}
@Override
public int getCount() {
return mApps.size();
}
@Override
public Object getItem(int position) {
return mApps.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
AppViewHolder holder;
if(convertView == null) {
convertView = mInflater.inflate(R.layout.row, null);
// creates a ViewHolder and stores a reference to the children view we want to bind data to
holder = new AppViewHolder();
holder.mTitle = (TextView) convertView.findViewById(R.id.apptitle);
holder.mIcon = (ImageView) convertView.findViewById(R.id.appicon);
convertView.setTag(holder);
} else {
// reuse/overwrite the view passed assuming(!) that it is castable!
holder = (AppViewHolder) convertView.getTag();
}
App app = mApps.get(position);
holder.setTitle(app.getTitle());
if (mIcons == null || mIcons.get(app.getPackageName()) == null) {
holder.setIcon(mStdImg);
} else {
holder.setIcon(mIcons.get(app.getPackageName()));
}
return convertView;
}
/**
* Sets the list of apps to be displayed.
*
* @param list the list of apps to be displayed
*/
public void setListItems(List<App> list) {
mApps = list;
}
/**
* Sets the map containing the icons for each displayed app.
*
* @param icons the map which maps the app's package name to its icon
*/
public void setIcons(Map<String, Drawable> icons) {
this.mIcons = icons;
}
/**
* Returns the map containing the icons for each displayed app.
*
* @return a map which contains a mapping of package names to icon drawable for all displayed apps
*/
public Map<String, Drawable> getIcons() {
return mIcons;
}
/**
* A view holder which is used to re/use views inside a list.
*/
public class AppViewHolder {
private TextView mTitle;
private ImageView mIcon;
/**
* Sets the text to be shown as the app's title
*
* @param title the text to be shown inside the list row
*/
public void setTitle(String title) {
mTitle.setText(title);
}
/**
* Sets the icon to be shown next to the app's title
*
* @param img the icon drawable to be displayed
*/
public void setIcon(Drawable img) {
if (img != null) {
mIcon.setImageDrawable(img);
}
}
}
}
and i call it using :
mAdapter = new AppListAdapter(getApplicationContext(), aList, R.layout.lv_layout, from, to);
mAdapter.setListItems(mApps);
Upvotes: 0
Views: 230
Reputation: 2002
Just add the footer to the list view
View footer = getLayoutInflater().inflate(R.layout.footer, null);
Footer View can be the Button
listView.addFooterView(footer);
Upvotes: 1
Reputation: 3585
Make your parent layout as ScrollView
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
>
<RelativeLayout
android:layout_width="318dp"
android:layout_height="495dp"
>
<LinearLayout
android:id="@+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal"
>
<TextView
android:id="@+id/maTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="180dip"
android:gravity="center_vertical|center_horizontal"
android:text="Ajouter Bloquer" />
</LinearLayout>
<ListView
android:id="@+id/lv_countries"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linear"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:clickable="true"
tools:context=".MainActivity" />
<LinearLayout
android:id="@+id/linear1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/lv_countries"
android:orientation="horizontal"
>
<Button
android:id="@+id/button25"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Valider" >
</Button>
</LinearLayout>
</RelativeLayout>
Upvotes: 0