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.
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.
I need to allow user to CLICK anywhere on the screen, so I've implemented onClick listener for mainLayout and it worked great.
But the problem is I've got to add a scrollview inside mainLayout to support small screen sizes and after adding scrollview, it blocks the parentLayout (in my case mainLayout) CLICK EVENT.
Just to exaplin this, a sample layout is as follows.
<!-- MAIN LAYOUT WHERE I NEED
THE CLICK EVENT-->
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bebebe"
android:orientation="vertical"
android:onClick="onClick_MainLayout">
<ScrollView
android:id="#+id/mainScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="#+id/button1"
android:layout_width="100dp"
android:layout_height="40dp"
android:text="TEST BUTTON 1"
android:onClick="onClick_Button1"/>
<Button
android:id="#+id/button2"
android:layout_width="100dp"
android:layout_height="40dp"
android:text="TEST BUTTON 2"
android:onClick="onClick_Button2"/>
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Text View"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
I searched for this and found various ideas like disableing onClick manually in all other views inside scrollview etc but non of them works.
NOTE: I tried both implementing onClick listener manually in java and adding android:onClick="onClick_MainLayout" in to layout. Both the same.
EDITS ----------------------
All the changes I've done as you (#IntelliJ Amiya) mentioned is as below. Please let me know anything is missing.
<RelativeLayout
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bebebe">
<ScrollView
android:id="#+id/mainScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button1"
android:layout_width="100dp"
android:layout_height="40dp"
android:text="TEST BUTTON 1"/>
<Button
android:id="#+id/button2"
android:layout_below="#+id/button1"
android:layout_width="100dp"
android:layout_height="40dp"
android:text="TEST BUTTON 2"/>
<TextView
android:id="#+id/textview1"
android:layout_below="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Text View"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
And in on create
findViewById(R.id.mainLayout).setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Log.v("MyLogs", "Click Event Fires...");
}
});
Your Scroll view overlaps the linear layout i.e #mainLayout,so
set its height to wrap content
then you can perform onclick for both scroll view buttons and mainlayout.
Pls tell me if i wrong.
<ScrollView
android:id="#+id/mainScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bebebe"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:id="#+id/mainScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="#+id/button1"
android:layout_width="100dp"
android:layout_height="40dp"
android:text="TEST BUTTON 1"
android:onClick="onClick_Button1"/>
<Button
android:id="#+id/button2"
android:layout_width="100dp"
android:layout_height="40dp"
android:text="TEST BUTTON 2"
android:onClick="onClick_Button2"/>
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Text View"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
JAVA
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick_Button1(View v)
{
Toast.makeText(this, "1ST Button Click", Toast.LENGTH_SHORT).show();
}
public void onClick_Button2(View v)
{
Toast.makeText(this, "2ND Button Click", Toast.LENGTH_SHORT).show();
}
}
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 want to have two buttons top of a listview. If I scroll below the listview I want that the buttons stay at top. I searched through many solutions on stackoverflow however I could not find the exact one for my case.
My layout xml(mainlayout.xml):
<?xml version="1.0" encoding="utf-8"?>
<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"
android:orientation="horizontal">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/latest_news_button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/tracked_news_button" />
</LinearLayout>
<ListView
android:id="#+id/mylist"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
The graphical layout produced is just what I wanted:
Here is my code to use this layout, in case I might fail to bind the Java code to layout;
public class MainActivity extends ListActivity{
Button latestButton;
Button trackedButton;
ListView lv = null;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainlayout);
latestButton = (Button)findViewById(R.id.button1);
latestButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Latest Button!", Toast.LENGTH_LONG).show();
}
});
trackedButton = (Button)findViewById(R.id.button2);
trackedButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Tracked Button!", Toast.LENGTH_LONG).show();
}
});
this.lv = getListView();
String[] values = new String[]{"asdfa","qwerqwer","banbn"};
lv.setAdapter(new ArrayAdapter<String>(BilTrackerMainActivity.this, android.R.layout.simple_expandable_list_item_1, values));
}
however when this activity is called from my other activity my app unfortunately closed. LogCat says:
Your content must have a ListView whose id attribute is 'android.R.id.list'
But I try adding lv = (ListView)findViewById(R.id.mylist); instead of this.lv = getListView();. I could not solve this issue.
I am aware of ListView#addHeaderView but I want to solve my particular problem with using this kind of layout.
Just change your listview id to android:id="#android:id/list"
Use a RelativeLayout. Place the second button to the right of the first button using layout_toRightOf then place the listview beneath button one using layout_below. Something like this (I haven't tested it, apologies for any typos)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/latest_news_button" />
<Button
android:id="#+id/button2"
android:layout_toRightOf="#id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/tracked_news_button" />
<ListView
android:id="#+id/mylist"
android:layout_below="#id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Here is the xml you are looking for
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF394952">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
style="#android:style/ButtonBar">
<Button
android:id="#+id/btn_AddMore"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/newItem"
android:textColor="#FF394952"/>
</LinearLayout>
<ListView
android:id="#+id/game_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_weight="1.0" />
</LinearLayout>
And when you design Activity for this dont use List activity directly use Activity and set adapter on the ListView.
ListView lv = (ListView) findViewById(R.id.game_list);
ArrayAdapter<String> listItem = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, ALBUM_NAME);
lv.setAdapter(listItem);
lv.setTextFilterEnabled(true);
Use below xml file for that
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/mLlayout1" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/latest_news_button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/tracked_news_button" />
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/mLlayout1" >
</ListView>
</RelativeLayout>
Create FrameLayout with [your ListView] and [LinearLayout with your buttons].
Do once something like this within onCreate()
LinearLayout myButtons = ...;
myButtons.bringToFront();
So, your ContentView will have a FrameLayout with two child, one of those is in foreground.
That's all. Hope it helped))
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>