Similar to the contacts view on the androids contacts section, which has the search bar on top with a dynamic list view below it, example here, I am trying to have a spinner instead of a text field.
My problem is that in the layout, the Spinner repeats per list view item.
I have the following list.xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/row"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sc" />
<TextView
android:id="#+id/rowData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
and the follow Java:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
application = ((MyAppApplication) getApplication());
populateOffers();
}
private void populateOffers()
{
MyAppRequestor MyApp = new MyAppRequestor();
ArrayList<String> list = MyApp.items(application.getMyAppId());
adapter = new ArrayAdapter<String>(this,
R.layout.list, R.id.rowData, list);
setListAdapter(adapter);
}
Since you are using list.xml as your layout it will be repeated.. If you want spinner only once, then you have to put in the main layout (Layout where you have defined the list view as a component.
try this list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/bgd" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sc" />
<TextView
android:id="#+id/rowData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Related
Here is my MainActivity:
public class MainActivity extends AppCompatActivity {
private LinearLayout mStatusBarAllContents;
private FrameLayout mStatusBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mStatusBar = findViewById(R.id.status_bar);
mStatusBarAllContents = findViewById(R.id.status_bar_all_contents);
mStatusBar.setOnClickListener(v -> {
Log.d("TAG", "status");
});
mStatusBarAllContents.setOnClickListener(v -> {
Log.d("TAG", "statusall");
});
}
My Layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/status_bar"
android:layout_width="match_parent"
android:layout_height="60px"
android:background="#drawable/sysheader_bg"
android:descendantFocusability="afterDescendants"
android:orientation="vertical">
<ImageView
android:id="#+id/notification_lights_out"
android:layout_width="22dip"
android:layout_height="match_parent"
android:paddingStart="6dp"
android:paddingBottom="2dip"
android:scaleType="center"
android:visibility="gone"
tools:ignore="RtlCompat" />
<LinearLayout
android:id="#+id/status_bar_all_contents"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<FrameLayout
android:layout_width="174px"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/clock_relativelayout"
android:layout_width="174px"
android:layout_height="match_parent"
android:clickable="true"
android:visibility="visible">
<TextView
android:id="#+id/clock_hour"
android:layout_width="60px"
android:layout_height="54px"
android:gravity="center"
android:includeFontPadding="false"
android:text="05"
android:textColor="#color/white"
android:textSize="52px"
android:textStyle="bold" />
<ImageView
android:id="#+id/clock_coron"
android:layout_width="12px"
android:layout_height="48px"
android:layout_marginTop="9px"
android:layout_toRightOf="#+id/clock_hour"
android:scaleType="fitCenter"
android:src="#drawable/num_12x48_colon" />
<TextView
android:layout_width="60px"
android:layout_height="54px"
android:layout_toRightOf="#+id/clock_coron"
android:gravity="center"
android:includeFontPadding="false"
android:text="30"
android:textColor="#color/white"
android:textSize="52px"
android:textStyle="bold">
</TextView>
</RelativeLayout>
</FrameLayout>
<LinearLayout
android:id="#+id/status_bar_info_layout"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:visibility="visible">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/audio_area"
android:layout_width="786px"
android:layout_height="match_parent"
android:background="#drawable/da_header_sections_background_click_over_info"
android:clickable="true"
android:orientation="horizontal"
android:splitMotionEvents="false">
<FrameLayout
android:id="#+id/audio_info_area"
android:layout_width="708px"
android:layout_height="match_parent"
android:clickable="false">
<TextView
android:id="#+id/audio_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="18px"
android:layout_marginLeft="18px"
android:ellipsize="end"
android:gravity="left"
android:singleLine="true"
android:text="ALOLO"
android:textSize="20sp"
android:visibility="visible" />
<LinearLayout
android:id="#+id/audio_off"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="24px"
android:paddingLeft="24px"
android:paddingEnd="56px"
android:paddingRight="56px"
android:visibility="gone">
<TextView
android:id="#+id/audio_off_text"
android:layout_width="648px"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="6px"
android:layout_marginLeft="6px"
android:ellipsize="end"
android:gravity="left"
android:singleLine="true"
android:text="PowerOFF"
android:textColor="#color/white"
android:textSize="30px">
</TextView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</LinearLayout>
I set onclick on FrameLayout and LinearLayout, i wanna show log is status but when i touch it, nothing happen.
And then, i set android:layout_width="1dp", android:layout_height="1dp" of id: status_bar_all_contents, it show log: status, but status_bar_all_contents will gone, so i dont want that.
So how to fix when i touch it and show log status?
Ps: Sorry for my english is not good.
Layouts typically pass-through clicks to their children.
You can try this solution here disabling all children onclicks and enabling the FrameLaoyuts onclicks. But I don't think that will work with the LinearLayout on top of that.
Android frame layout click listener not working
My advice wrap the entire view in a ConstraintLayout, and position 2 basic <View>s
One <View> that is constrained to match the FrameLayout
One <View> that is constrained to match the LinearLayout
These <View>s will act as overlays.
<View
android:id="#+id/status_bar_overlay"
app:layout_constraintEnd_toEndOf="#id/status_bar"
app:layout_constraintStart_toStartOf="#id/status_bar"
app:layout_constraintTop_toTopOf="#id/status_bar"
app:layout_constraintBottom_toBottomOf="#id/status_bar" />
<View
android:id="#+id/status_bar_all_contents_overlay"
app:layout_constraintEnd_toEndOf="#id/status_bar_all_contents"
app:layout_constraintStart_toStartOf="#id/status_bar_all_contents"
app:layout_constraintTop_toTopOf="#id/status_bar_all_contents"
app:layout_constraintBottom_toBottomOf="#id/status_bar_all_contents" />
Set the two View's onClickListener in the Activity and there you go.
My problem is when i click list item in main layout some time it's triggered but not all time.
I don't know how to solve this problem?.
Please help me..
My code is:
View v = convertView.findViewById(R.id.chat_window_single);
v.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.i("position",v.getTag().toString());
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putLong("eventId", groupEventMoList.get(Integer.parseInt(v.getTag().toString())).getEventId());
editor.putString("eventTitle",groupEventMoList.get(Integer.parseInt(v.getTag().toString())).getText());
editor.commit();
Intent groupAct = new Intent(context, GroupChatActivity.class);
startActivity(groupAct);
}
});
My layout file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/chat_window_single"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="#+id/chat_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5sp"
android:shadowDx="1"
android:shadowDy="1"
android:textColor="#android:color/primary_text_light"
android:textSize="20sp" >
</TextView>
<TextView
android:id="#+id/event_place"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5sp"
android:shadowDx="1"
android:shadowDy="1"
android:textColor="#android:color/primary_text_light"
android:textSize="20sp" >
</TextView>
<TextView
android:id="#+id/event_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5sp"
android:shadowDx="1"
android:shadowDy="1"
android:textColor="#android:color/primary_text_light"
android:textSize="20sp" >
</TextView>
</LinearLayout>
My main layout file :
<?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/chat_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="80dp" >
</ListView>
</LinearLayout>
Any Help would be appreciated.
Your textviews are stealing the focus from parent list view, make them clickable and focusable = false also the upermost linear layout needs android:descendantFocusability="blocksDescendants"
i'm in serious problem. I'm trying to get EditText from tab1 in Tabhost, but it keeps giving me error:
Attempt to invoke virtual method 'android.view.View android.widget.LinearLayout.findViewById(int)' on a null object reference.
I have tried my code in many many different ways without any success!
Here is my Code :
final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View control_layout = inflater.inflate(R.layout.control_layout,null,false);
TabHost tbhst = (TabHost)control_layout.findViewById(R.id.tabHost);
tbhst.setup();
TabHost.TabSpec tb1 = tbhst.newTabSpec("TAB 1");
TabHost.TabSpec tb2 = tbhst.newTabSpec("TAB 2");
TabHost.TabSpec tb3 = tbhst.newTabSpec("TAB 3");
tb1.setContent(R.id.tab1);
tb2.setContent(R.id.tab2);
tb3.setContent(R.id.tab3);
tb1.setIndicator("CMD");tb2.setIndicator("Chat");tb3.setIndicator("Control");tbhst.addTab(tb3);tbhst.addTab(tb2);tbhst.addTab(tb1);
LinearLayout gff = (LinearLayout)tbhst.findViewById(R.id.ggf);
FrameLayout tbs_content = (FrameLayout)gff.findViewById(android.R.id.tabcontent);
LinearLayout tbs1 = (LinearLayout)tbs_content.findViewById(R.id.tab1);
final EditText command_resualt_box = (EditText) tbs1.findViewById(R.id.editText5);
UPDATE :
as #popvitsj said maybe i'm making mistake but i tried to change it in layout/control.xml, but it gives me another different error and here is a Screenshot :
and this the code in layout/control.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/control_q">
<TabHost
android:layout_width="fill_parent"
android:layout_height="410dp"
android:id="#+id/tabHost"
android:layout_gravity="center_horizontal">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/ggf">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></TabWidget>
<FrameLayout
android:id="#+id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout"
android:layout_gravity="center_horizontal">
<EditText
android:layout_width="match_parent"
android:layout_height="35dp"
android:id="#+id/editText9"
android:inputType="text"
android:imeOptions="actionDone"
android:background="#android:color/black"
android:textColor="#ffff0c00"
android:layout_marginTop="5dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="300dp"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/editText10"
android:enabled="false"
android:background="#android:color/black"
android:textColor="#ffff0c00"
android:autoLink="all"
android:layout_marginTop="5dp"
android:scrollbars="horizontal|vertical"
android:linksClickable="true"
android:editable="false" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:id="#+id/linearLayout2" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<EditText
android:layout_width="260dp"
android:layout_height="40dp"
android:id="#+id/editText11"
android:background="#android:color/black"
android:textColor="#ffff0c00"
android:layout_marginLeft="5dp"
android:layout_marginTop="2.5dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button11"
android:id="#+id/button12"
android:background="#android:color/black"
android:textColor="#ffff0c00"
android:layout_marginLeft="5dp" />
</LinearLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="300dp"
android:enabled="false"
android:inputType="textMultiLine"
android:background="#android:color/black"
android:textColor="#ffff0c00"
android:autoLink="all"
android:ems="10"
android:id="#+id/editText12"
android:layout_gravity="center_horizontal"
android:layout_weight="0.53"
android:layout_marginTop="5dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
NOTE : this code is giving an error you can take look on screenshot above.
FrameLayout tbs_content = (FrameLayout)gff.findViewById(android.R.id.tabcontent);
LinearLayout tbs1 = (LinearLayout)tbs_content.findViewById(R.id.tab1);
The second of these lines gives the NullPointerException. So tbs_content is null, because it fails to load it on the first line.
It looks like you made a mistake specifying the id: android.R.id.tabcontent should most likely be R.id.tabcontent.
android.R is the R-class for the system resources. R is usually your own generated class (unless you import android.R).
I'm trying to inflate a list of views in a LinarLayout directly in the onCreate() method from the activity. However, I'm having a problem somewhere in the code but I really can't see it, I'm turning around this problem for two days, I'm going crazy !
The problem is that when I run the activity, the linear layout is completely empty, there is only the title.
Here is the important part of the code, KeyItems activity :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.keyitems_layout);
initializer();
ll = (LinearLayout) findViewById(R.id.ll);
LayoutInflater inflater = LayoutInflater.from(this);
for (int i = 0; i < list.size(); i++) {
View view = inflater.inflate(R.layout.keyitem_temp, ll, false);
final TextView ind = (TextView) view.findViewById(R.id.ind);
final TextView item = (TextView) view.findViewById(R.id.item);
ind.setText(list.get(i).get("id"));
item.setText(list.get(i).get("item"));
ll.addView(view);
}
}
Here is the keyitems_layout :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/black" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/black">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/key_items"
android:textSize="36sp"
android:textColor="#color/white" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp" />
<LinearLayout android:id="#+id/ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:orientation="vertical"
android:background="#color/white" >
</LinearLayout>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:text="caca"
android:padding="32dp" />
</LinearLayout>
</ScrollView>
And finally, my keyitem_temp.xml which I'm inflating :
<?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="wrap_content"
android:background="#color/black"
android:padding="4dp"
android:orientation="horizontal" >
<TextView android:id="#+id/ind"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:textSize="18sp"
android:textColor="#color/blue" />
<TextView android:id="#+id/item"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:textSize="18sp"
android:textColor="#color/white"/>
</LinearLayout>
I have an other activity called ItemsActivity which is the same code with some little differences and it works. Any suggestion? Thanks in advance.
Try using wrap_content for all of your heights except the initial ScrollView:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/black" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/black">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/key_items"
android:textSize="36sp"
android:textColor="#color/white" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp" />
<LinearLayout android:id="#+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:orientation="vertical"
android:background="#color/white" >
</LinearLayout>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:text="caca"
android:padding="32dp" />
</LinearLayout>
</ScrollView>
and:
<?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="wrap_content"
android:background="#color/black"
android:padding="4dp"
android:orientation="horizontal" >
<TextView android:id="#+id/ind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="18sp"
android:textColor="#color/blue" />
<TextView android:id="#+id/item"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="18sp"
android:textColor="#color/white"/>
</LinearLayout>
I am using linear layout inside that one button and one list view..
list-view is adding its item dynamically at the run-time..
so at that time button goes behind list-view and not visible and list-view fit in whole layout.
I want to put Button above the List view and it must also stay after loading list-view
Thanks in Advance
my .xml file is:
<?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"
android:background="#000000">
<Button
android:id="#+id/btn_searchNewDevices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_gravity="left"
android:background="#000000"
android:textColor="#FFFFFF"
android:text="Search New Devices"
/>
<ListView
android:id="#+id/lst_add_newDevices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal" >
</ListView>
</LinearLayout>
here it is search new device button.
click on that button device search for Bluetooth and add into listview
so this is thing happen in my application..
I think even this works.Give a try
edited...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/btn_searchNewDevices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="5dip"
android:text="Search New Devices"
android:textColor="#000000" />
<ListView
android:id="#+id/lst_add_newDevices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/btn_searchNewDevices"
android:scrollbars="horizontal">
</ListView>
</RelativeLayout>
and the activity is as follows .
public class MainActivity extends Activity implements OnClickListener {
ArrayAdapter<String> adapter;
private Button mBTNSearch;
private static ListView mLV_list;
ArrayList<String> devicesList;
SparseBooleanArray checked;
RelativeLayout layout;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBTNSearch = (Button) findViewById(R.id.btn_searchNewDevices);
devicesList = new ArrayList<String>();
mLV_list = (ListView) findViewById(R.id.lst_add_newDevices);
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, devicesList);
mBTNSearch.setOnClickListener(this);
mLV_list.setAdapter(adapter);
}
public void onClick(View v) {
adapter.add("new Device");
adapter.notifyDataSetChanged();
}
}
The output capture is as below
Try using android:layout_weight="1" in the listview's height to that you make sure your button will always be seen in the screen.
You should try:
<?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:background="#000000"
android:orientation="vertical" >
<Button
android:id="#+id/btn_searchNewDevices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="5dip"
android:background="#000000"
android:text="Search New Devices"
android:textColor="#FFFFFF" />
<ListView
android:id="#+id/lst_add_newDevices"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="horizontal" >
</ListView>
</LinearLayout>
Or you can use ListView's addHeaderView() method. Here is a tutorial for that.
Try this code for your Layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</ListView>
</LinearLayout>
Try putting your listview inside a scrollview.
<Button
android:id="#+id/btn_searchNewDevices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="5dip"
android:background="#000000"
android:text="Search New Devices"
android:textColor="#FFFFFF" />
<ScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="7dip"
android:scrollbars="none" >
<ListView
android:id="#+id/lst_add_newDevices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal" >
</ListView>
</ScrollView>
It might work. I haven't tested, so not sure.