Hi everyone I ve been searching this a lot but I couldn't find an answer that would work in my case. In my layout i have a listview and outside the list and more specific above i have an imageview an editText which work as a search and a custom Button!The problem is that when i press the button does not start the Activity which i have put in th Intent.Why is this happening?I cannot find the error and so far i had never problem with button events.
Here is my xml:
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/imageView1"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:clickable="false"
android:layout_below="#+id/autoCompleteTextView1" >
</ListView>
</LinearLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="LIST OF PATIENTS"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#33B5E5" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="90dp"
android:layout_height="85dp"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_below="#+id/textView1"
android:padding="2dp"
android:src="#drawable/search_user" />
<LinearLayout
android:id="#+id/linear"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignBottom="#+id/autoCompleteTextView1"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<Button
android:id="#+id/add"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_above="#+id/linearLayout1"
android:layout_alignParentRight="true"
android:background="#drawable/buttonadd"
android:onClick="button_click"
android:src="#drawable/add" />
</LinearLayout>
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView1"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_toLeftOf="#+id/linear"
android:ems="10"
android:hint="Search patient" />
the button is the right on the top next to autocomplete.In the .java doc i have right this code as far as concerned the button:
In the onCreate
addp=(Button) findViewById(R.id.add);
addp.setOnClickListener(this);
In th onClick
case R.id.add:
Intent add= new Intent(sqlviewpatients.this,afprognosis.class);
startActivity(add);
break;
I ve been doing the same thing to others button and they working only this one does not respond to onClick events.Please tell me what I am doing wrong?
thanks in advance
This is because your ids do not match:
addp=(Button) findViewById(R.id.add);
and:
<Button
android:id="#+id/addpatient"
Change the java to:
addp=(Button) findViewById(R.id.addpatient);
EDIT: If you are defining your onClick within the XML then you should not need to set an onClickListener within the java code. Just make the code:
Intent add= new Intent(sqlviewpatients.this,afprognosis.class);
startActivity(add);
within a method that is called button_click.
EDIT after Code update
Okay, after reading the code you just posted: sqlviewpatients:
what does customwindow3 look like? Does it inherit from ListActivity or what?
This class only implements onClickListener and so a bunch of code won't get executed, including onCreate unless of course, customwindow3 does
Original
1) your button's id is addpatient not add which is the clause if you switch statement
2) have you looked into doing this:
public void button_click(View v)
{
Intent .....
}
Also, from the snippet you posted this:
addp=(Button) findViewById(R.id.add);
addp.setOnClickListener(this);
shouldn't actually run (you'll get a null pointer exception) since there is no element with that id (unless of course you've defined that somewhere else and didn't show us).
First of all thanks everyone for your answers and your time!I appreciate it
Second i found where the error was. the onClick method should have an #overide above
Related
not urgent as I have a work around, however I would really like to understand whether there is a reason for a behaviour I observe when i make the changes below.
I have a simple layout with an EditText and a Button in an XML file.
It displays fine, and as the code below it works fine (triggering onClick)
<RelativeLayout android:id="#+id/group"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<EditText android:id="#+id/Topic" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toLeftOf="#+id/AddTopic"
android:layout_alignParentLeft="true" android:ems="10" />
<Button android:id="#+id/AddTopic"
android:layout_alignParentRight="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:onClick="onClick" android:textSize="10dp" android:text="Add Topic" />
</RelativeLayout>
However, if I flip the objects around, as below, the button does not trigger - onClick does not run and nothing happens.
<RelativeLayout android:id="#+id/group"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button android:id="#+id/AddTopic"
android:layout_alignParentRight="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:onClick="onClick" android:textSize="10dp" android:text="Add Topic" />
<EditText android:id="#+id/Topic" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toLeftOf="#+id/AddTopic"
android:layout_alignParentLeft="true" android:ems="10" />
</RelativeLayout>
I might be missing something really obvious here, and as I say it doesn't matter in the sense it works in the first structure, but it does matter in the sense I would really like to know why. Any ideas appreciated.
Combining the information posted in the comments, the likely reason is the fact that you mistakenly use #+id/ when referring to other objects, instead of #id/. Specificly EditText contains android:layout_toLeftOf="#+id/AddTopic". The + sign should only be used when introducing new ids.
In the first example it is not harmful for the listener, since the button is declared after the EditText and #+id/ works as should, but in your second example the id of the button might be overriden when you declare the EditText.
TL;DR: in EditTextreplace android:layout_toLeftOf="#+id/AddTopic" with android:layout_toLeftOf="#id/AddTopic". Do this even if you use your "work around".
I have RelativeLayouts in HorizontalScrollView. When a user clicks on one of the layouts (or any of its childs) I need to change the background color of the certain RelativeLayout and get its ID for further process. I saw this might be done with DuplicateParentState or with onTouchEvent. Which way is recommended?
My XML file after editing the XML file as proposed:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<youme.appyoume.com.ExDialog>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:clickable="true"
android:duplicateParentState="true"
android:onClick="onClick"
android:src="#drawable/ic_launcher" />
<EditText
android:id="#+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:duplicateParentState="true"
android:ems="10"
android:focusable="false"
android:focusableInTouchMode="false"
android:inputType="textMultiLine"
android:text="text" >
<requestFocus />
</EditText>
</youme.appyoume.com.ExDialog>
</RelativeLayout>
Thanks,
Simon
If you want to use the custom class youve created in your xml you just use the entire root name of the object. So for instance if you have a class in
com.your.package.customButton
you would write in your xml
<RelativeLayout
...layoutstuff config>
<com.your.package.customButton
...customButton layout config/>
</RelativeLayout>
if your subclassing a relativelayout you would use it like this
<youme.appyoume.com.ExDialog
...layout setup stuff>
<Button
...button setup stuff
/>
</youme.appyoume.com.ExDialog>
You could always assign a tag to it for future reference using setTag and getTag and just use setOn Click Listener and put what ever you need to happen in there
I'm trying to create a custom view component which looks like this:
a component will work as a menu - it has 4 imageviews inside which react to onClick event.
I made a separate .xml with them and a class for it. Than i set the parent node class from .xml "class = 'myclass'".
In my .xml an imageview has a onClick declared, but when i try to handle it using myclass - application crashes. What is wrong? Or I suppose the main question is: what is a right way to set event handlers for a custom view?Handlers which are in this views class definition. Should I write in .xml of a view something like
Addition: how do I, then, can fire events from this custom view for activity which will hold it to handle?
Here is my menu .xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
class="com.example.mtgesturestest.MTMenuViewController"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/main_layout" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/imageChannels"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="#drawable/channels"
android:layout_marginBottom="10dp" />
<ImageView
android:id="#+id/imageMessages"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="#drawable/messages"
android:layout_marginBottom="10dp" />
<ImageView
android:id="#+id/imageTimeline"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="#drawable/timeline"
android:onClick="yell"
android:layout_marginBottom="10dp" />
</RelativeLayout>
<ImageView
android:id="#+id/imageMenu"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/menu"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-15dp"
android:onClick="maximizeMenu"/>
</RelativeLayout>
Application says it cant find onClick handler (maximizeMenu), but its searching it in the activity where I add this view instead of com.mtgesturestest.MTMenuViewController class. I want this menu to be independent. It should handle click, play some animation and then fire event for parent activity. So you can say that this onClick here is for inner use of my custom view.
Why not try to add the onClick listener from inside the MTMenuViewController class like
ImageView menu = (ImageView)this.findViewById(R.id.imageMenu);
menu.setOnClickListener(PUT THE LISTENER HERE);
I have a default ListView that i have added my custom views for the list items, but the buttons inside of these views are not clickable most of the time. I output a Log.v when the button receives a click event, but i have to tap the button almost a dozen times before it will register the click.
The other problem related tot his that i am having is that when the button is pressed i want an animation to happen revealing a menu sliding out from beneath it. At the moment i have tried several different methods like making a custom class for the views versus just using a layout inflater to get the relativeLayout object for the view, but nothing is working properly. I have even tried using listview.getAdapter().notifyDataSetChanged(); but that only has a pop-into-place for the extended view when i want an animation.
I have searched everywhere and it seems like the only possible solutions are to either rewrite my own custom listview or to use a linearlayout with a scrollview. The latter seems easier but i dont think it is nearly as optimized as the listview is.
Any suggestions would be greatly appreciated, if you need to see some code, please let me know...
Thanks!
UPDATE:
the getView() contains this:
Holder hold;
convertView = friends.get(position);
hold = new Holder();
hold.pos = position;
convertView.setTag(hold);
return convertView;
basically i pass an ArrayList<RelativeLayout>, at the moment, to the Adapter so that i dont have to create a new view each time and so that the animation will stay animated when i scroll down...
inside the OnCreate() for this activity i set that ArrayList<RelativeLayout> with this next code, but this is only temporary as i plan to use another method later, like an Async task or something so that this view contains some data...
RelativeLayout temp;
for(int i=0; i<30; i++){
temp = (RelativeLayout) inflater.inflate(R.layout.list_item, null);
final LinearLayout extraListItemInfo = (LinearLayout) temp.findViewById(R.id.extraListItemInfo);
Button infoBtn = (Button) temp.findViewById(R.id.infoBtn);
infoBtn.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Log.v("ListItem", "Button has been clicked... ");
extraListItemInfo .setVisibility(View.VISIBLE);
ExpandAnimation closeAnim = new ExpandAnimation(extraListItemInfo , animHeight);
closeAnim.setDuration(750);
closeAnim.setFillAfter(true);
if(extraListItemInfo .getTag() == null || !extraListItemInfo .getTag().equals("expanded")){
extraListItemInfo .getLayoutParams().height = 0;
friendInfoList.startAnimation(closeAnim.expand());
extraListItemInfo .setTag("expanded");
}else if(extraListItemInfo .getTag().equals("expanded")){
extraListItemInfo .startAnimation(closeAnim.collapse());
extraListItemInfo .setTag("closed");
}
//((BaseAdapter) listview.getAdapter()).notifyDataSetChanged(); i tried it here once but then left it
//as the only action inside the listview's onitemclick()
}
});
listItems.add(temp);
}
this is the list item that i am using:
<?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:background="#color/darkgrey"
android:paddingBottom="5dp" >
<LinearLayout
android:id="#+id/extraListItemInfo "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/listItemInfo"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="-10dp"
android:background="#color/grey"
android:orientation="vertical"
android:visibility="gone" >
<RelativeLayout
android:id="#+id/RelativeLayout04"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_list_height"
android:layout_marginTop="5dp" >
<ImageView
android:id="#+id/ImageView04"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView04"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout03"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_list_height" >
<ImageView
android:id="#+id/ImageView03"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView03"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout02"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_list_height" >
<ImageView
android:id="#+id/ImageView02"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView02"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_list_height" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/imageView1"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_list_height">
<ImageView
android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView01"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/listItemInfo"
android:layout_width="wrap_content"
android:layout_height="95dp"
android:background="#drawable/friend_cell_background2x"
android:clickable="true" >
<RelativeLayout
android:id="#+id/leftLayout"
android:layout_width="90dp"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imgCompany"
android:layout_width="60dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:scaleType="centerInside"
android:src="#drawable/user2x" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
android:src="#drawable/online_indicator2s" />
</RelativeLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/leftLayout"
android:background="#android:color/transparent"
android:gravity="left|center"
android:orientation="vertical"
android:paddingLeft="5dp" >
<TextView
android:id="#+id/lblCompanyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contact Name"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/lblReawrdDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Played Offer"
android:textColor="#color/white"
android:textSize="17dp" >
</TextView>
</LinearLayout>
<ImageView
android:id="#+id/imageView4"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="5dp"
android:src="#drawable/facebook_btn2x" />
<Button
android:id="#+id/infoBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/imageView4"
android:background="#drawable/info_btn2x"
android:clickable="true" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="13dp"
android:layout_toLeftOf="#+id/infoBtn"
android:text="Follows 30+"
android:textColor="#color/white"
android:textSize="11dp" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="75dp"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/textView2"
android:background="#drawable/fan_btn2x"
android:text="Fans 30+"
android:textColor="#color/white"
android:textSize="11dp" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/imageView4"
android:src="#drawable/google_btn2x" />
</RelativeLayout>
</RelativeLayout>
sorry for any layout problems that may make things difficult to read... but i hope this helps you guys to understand my problem... Thanks
UPDATE 2:
All of these answers have been helpful in some way, but i think the main issue that i must first fix is why the buttons do not receive click events until i have first scrolled away from that listItem, then back to it, then clicked the button again... If someone can help find a solution to THAT i think that everything else will be much easier to solve...
Thanks...
A screenshot as requested, but remember that this shot was taken on a samsung galaxy tab 10.1 and due to me using the same layout for this larger screen, it looks much different from what it does on the phone i usually test with (Motorola droid x that isnt rooted and cant take screenshots...)
Another Update:
I managed to get the clicking and animation working nicely by Extending ArrayAdapter instead of base adapter. Sadly i am still experiencing problems as only the bottom half of the list is clickable. The top half of the list still behaves as before with the very glitchy click events... Any ideas as to what is happening this time? Thanks...
Well this isn't really an answer, but after rewriting this a few times I managed to fix it so that it functions exactly the way I wanted.
This time I left all of the data separate from each view and had each list item be a custom class inheriting RelativeLayout and also implementing its own OnClickListener for its specific infoBtn.
My adapter now simply extends ArrayAdapter<> and overrides this getView() method:
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView != null && (convertView instanceof FriendListItem2))
((FriendListItem2) convertView).setFriendInfo(friends.get(position));
else
convertView = new FriendListItem2(getContext(), friends.get(position));
return convertView;
}
Finally, in the main activity for this page I simply set the ListView with an adapter that I passed the data to.
This is all much cleaner than I had before and I wish it hadn't taken several rewrites of the code to get it right. Hopefully someone can benefit from this, though I still have no clue why I was getting a problem before.
Thanks for all previous suggestions.
try using this property in the top level layout in which your child views are placed.
android:descendantFocusability="blocksDescendants"
Its a bit tricky but I would suggest that if the above line does not work, try toggling between the removing of focusable=true and focusable="false" from the buttons. It should work.
Cheers!
That is a complex layout to create for every row...
Anyway, when you use the new keyword you are creating a different scope. In short your onClickListener does not see the 30 different extraListItemInfo references you expect it to see.
Try something like this:
#Override
public void onClick(View v) {
LinearLayout extraListItemInfo = v.getParent();
...
add android:onClick="onClick" to your button xml, it'll make it call the onClick() method
I had the same problem. Try taking the "android:clicable="true" " from the Relative Layout. When you do that the activity expects you to do make setOnClickListener to that RelativeLayout . It worked for me
you can fire click event on button from getView() method of ListViewAdapter Class.
See this question
Android : How to set onClick event for Button in List item of ListView.
My app is about creating surveys. In order to do so, the user should be able to create new fields dynamically.
So, when creating a new survey, an Activity is shown with only 2 buttons (add and delete). When a user clicks the add button, a row appears containing a EditText(so he can write the question), a Spinner(that enables user to select the type of field: text, RadioButton, CheckBox, etc..) and another EditText (in which the different available answer choices are written, if applicable).
To accomplish this I created a XML file containing these Widgets and each time the user clicks in the add button, the XML is inflated. It works the first time I press the button, but after that... nothing happens.
I read somewhere that you cannot inflate the same child 2 times in a parent unless it is done in a loop.
So, my questions are:
-> How can I get around this and obtain the desired effect?
-> Why doesn't this apply in a Loop?
Any help or hint is appreciated. Once again, thank you very much for all the support the community has given me.
NOTE: In the android documentation they speak about cloning an inflator but the information there is scarce and I couldn't find any other info about it.
SOurce code:
XML - Main cointainer:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/wrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/mds_new_addfield_button"
android:tag="new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Field"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
/>
<Button
android:id="#+id/mds_new_deletefield_button"
android:tag="delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete Field"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
XML -Inflated:
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TableRow>
<TextView
android:id="#+id/mdsnew_field_tv"
style="#style/dsn_field"
android:text="Field Name "
/>
<TextView
android:id="#+id/mdsnew_type_tv"
style="#style/dsn_field"
android:text="Type of Field "
/>
<TextView
android:id="#+id/mdsnew_choices_tv"
style="#style/dsn_field"
android:text="Choices"
/>
</TableRow>
<TableRow>
<EditText
android:id="#+id/mdsnew_fieldname_et"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Field Name"
android:textSize="18sp"
/>
<Spinner
android:id="#+id/mdsnew_type_sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:id="#+id/mdsnew_choices_et"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choices "
android:textSize="18sp"
/>
</TableRow>
</TableLayout>
Add Button:
LinearLayout myRoot = (LinearLayout) findViewById(R.id.wrapper);
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.mds_new_row, myRoot);
Your parent is a LinearLayout, and it looks like you intended a vertical orientation, but you haven't specified this. Try setting the orientation and see if that helps.