I do try to get text datas from JSON, i do. But when it is time to write they are not exactly fitting. My XML file is here...
<?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" >
<TextView
android:id="#+id/txt_questionAdjective"
android:layout_width="fill_parent"
android:layout_height="139dp"
android:layout_gravity="center_vertical"
android:layout_marginTop="15dp" />
<RadioGroup
android:id="#+id/grp_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/rdb_optionA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />
<TextView
android:id="#+id/txt_optionA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="#+id/rdb_optionB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />
<TextView
android:id="#+id/txt_optionB"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/rdb_optionC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />
<TextView
android:id="#+id/txt_optionC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="#+id/rdb_optionD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />
<TextView
android:id="#+id/txt_optionD"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
</LinearLayout>
And what it looks like after that.
How can i set C and D options next to radiobuttons ? Thanks in advance.
EDIT:SOLVED I deleted the textView parts in XML and used the for loop which #Gabriella Angelova provided me. That really helped. Thanks.
You could use the following code snipet to set the text of your radio buttons dynamically:
RadioGroup radioGroup = (RadioGroup)findViewById(R.id.grp_options);
for (int i = 0; i < radioGroup .getChildCount(); i++) {
((RadioButton) radioGroup.getChildAt(i)).setText(*your value from JSON*);
}
radioButton.setText("your text");
Related
I have created radio group with custom layout i.e. custom button.
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup
android:id="#+id/radio_group_rating"
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="3" >
<RadioButton
android:id="#+id/radio_platinum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:clickable="true"
android:drawablePadding="10dp"
android:drawableTop="#drawable/star_small_dis"
android:gravity="center"
android:text="#string/platinum" />
<RadioButton
android:id="#+id/radio_gold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:clickable="true"
android:drawablePadding="10dp"
android:drawableTop="#drawable/star_small_dis"
android:gravity="center"
android:text="#string/gold" />
<RadioButton
android:id="#+id/radio_silver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:clickable="true"
android:drawablePadding="10dp"
android:drawableTop="#drawable/star_small_dis"
android:gravity="center"
android:text="#string/silver" />
</LinearLayout>
</RadioGroup>
<Button
android:id="#+id/btn_submit"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#id/radio_group_rating"
android:text="#string/submit" />
And in Activity, I have below code,
final Dialog dialog = new Dialog(mActivity);
dialog.setContentView(R.layout.rating_cust_dialog_layout);
radioGroupRating = (RadioGroup) dialog.findViewById(R.id.radio_group_rating);
Button btnSubmit = (Button) dialog.findViewById(R.id.btn_submit);
btnSubmit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
int selectedRadioId = radioGroupRating.getCheckedRadioButtonId();
View radioButton = radioGroupRating.findViewById(selectedRadioId);
Integer selctedPosition = radioGroupRating.indexOfChild(radioButton);
dialog.dismiss();
}
});
dialog.show();
My issue is radio buttons are not getting clicked. I thought it's because of android:button="#null" So I replaced it with android:button="#drawable/star_dis" but still not getting clicked.
Its the android:button="#null", please remove it from the xml file completely.
Try using this simple xml layout.
<?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:orientation="vertical" >
<RadioGroup
android:id="#+id/radio_group_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radio_platinum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="platinum" />
<RadioButton
android:id="#+id/radio_gold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="gold" />
<RadioButton
android:id="#+id/radio_silver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="silver" />
</RadioGroup>
<Button
android:id="#+id/btn_submit"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="submit" />
</LinearLayout>
Only difference to my code is that I don't put clickable="true" in xml, if RadioGroup handles touch event by itself to manage child radio buttons you should remove that attribute as clickable is generally set to true automatically when you set an OnClickListener.
I've got some problem with positioning TextViews. Currently my layout looks like:
Text1: Text2
Text3: Text4
Ok, but when Text2 has 2 rows length or more I've got:
Text1: Text2:1
Text3: Text2:2/Text4
I don't know how to set up my layout to obtain view like:
Text1: Text2:1
Text2:2
Text3: Text4
Can somebody help me solve that problem?
XML code:
(...)
//Text1:
<TextView
android:id="#+id/tv_author_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_genre_label"
android:layout_toRightOf="#+id/img_Cover"
android:text="Author: "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
//Text2:
<TextView
android:id="#+id/tv_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tv_author_label"
android:layout_alignBottom="#+id/tv_author_label"
android:layout_toRightOf="#+id/tv_author_label"
android:text="Anonymous Anonymous"
android:textAppearance="?android:attr/textAppearanceMedium" />
//Text3:
<TextView
android:id="#+id/tv_availability_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_author_label"
android:layout_toRightOf="#+id/img_Cover"
android:
android:textStyle="bold"
android:text="Availability: "
android:textAppearance="?android:attr/textAppearanceMedium" />
//Text4:
<TextView
android:id="#+id/tv_availability"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tv_availability_label"
android:layout_alignBottom="#+id/tv_availability_label"
android:layout_toRightOf="#+id/tv_availability_label"
android:layout_alignParentLeft="#+id/tv_availability_label"
android:layout_below="#+id/tv_author"
android:text="b/d"
android:textAppearance="?android:attr/textAppearanceMedium" />
(...)
you can reconstruct your code something like this,
<LinearLayout 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"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<TextView
android:id="#+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dfsdjfkd dsfsdf sdfsdf sdfsdfsd fjlsdjf sdj; j; jlksdfjl sdjflkdsjflsdk jkldsjf lsjldkfj sdl" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<TextView
android:id="#+id/tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</LinearLayout>
I hope it will be helpful !!
You can encapsulate the row of text views inside a linear layout with orientation - horiontal
I'm actually coding an app for Android and I need some help to do something.
I need to do a kind of popup message with this image: http://img716.imageshack.us/img716/9331/postitz.png. This image must have 2 TextView, one of them is a title and the other one is the message.
I have tried some options like Dialog with its own layout, own style, but the image fills all the screen instead of wrap the content of the TextViews. I have also tried to do it with a new Activity and occurs the same, the Image fills all the screen.
My actual layout is this:
<?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:gravity="center_vertical"
android:background="#android:color/white">
<LinearLayout
android:id="#+id/img_postit"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/postit"
android:orientation="vertical">
<TextView
android:id="#+id/note_titulo"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="30dp"/>
<TextView
android:id="#+id/note_descr"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="30dp"/>
</LinearLayout>
</LinearLayout>
But I have tried with a lot of different combinations, RelativeLayout, FrameLayout, and I cannot find the solution to do this.
Any idea of how to resolve it?.
Thank's for all.
you said you used as a new activity. Did you use android:theme="#android:style/Theme.Dialog in your manifest file?
And be sure that the image is little bit smaller one such that it will be suitable to act as a pop up..
If you used a dialog what exactly is the problem? Didnt you get the dialog as a pop up ?
(i think the image is larger so that it might fill the entire screen)
Create your own class extending dialog.And use layout like following. I use this in one of my apps and the dialog window is wrapped around the buttons :
<?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="wrap_content"
android:background="#drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/ll2"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_below="#+id/ll1"
android:gravity="left"
android:orientation="horizontal"
android:paddingBottom="5dp" >
<RadioButton
android:id="#+id/start"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/stop"
android:background="#drawable/start_on"
android:button="#android:color/transparent"
android:checked="true" />
<RadioButton
android:id="#+id/stop"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="#drawable/stop_off"
android:button="#android:color/transparent" />
<RadioButton
android:id="#+id/restart"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/stop"
android:background="#drawable/restart_on"
android:button="#android:color/transparent" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/lltext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/detail_credit"
android:layout_below="#+id/ll2"
android:layout_marginBottom="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/startText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/stopText"
android:text="#string/start_server_icon"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/stopText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:text="#string/stop_server_icon"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/restartText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/stopText"
android:text="#string/restart_server_icon"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_below="#+id/lltext"
android:layout_centerHorizontal="true"
android:text="OK" />
</RelativeLayout>
final Dialog dialog_my = new Dialog(FIRST.this,
android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialog_my.setContentView(R.layout.about_us); //<PUT YOUR LAYOUT ID HERE>
TextView date = (TextView) dialog_my.findViewById(R.id.date);
TextView thought = (TextView) dialog_my.findViewById(R.id.thought);
TextView ok = (TextView) dialog_my.findViewById(R.id.ok);
TextView link = (TextView) dialog_my.findViewById(R.id.link);
TextView contact = (TextView) dialog_my.findViewById(R.id.contact);
WindowManager.LayoutParams lp = dialog_my.getWindow().getAttributes();
lp.dimAmount = 0.0f;
dialog_my.getWindow().setAttributes(lp);
dialog_my.getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog_my.show();
when i try to set the text of an textview i get a nullpointerexception. somehow the findviewbyid method return null but i dont know why.
this is my xml file:
<?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="wrap_content" >
<RelativeLayout
android:id="#+id/rl_ros_layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="#+id/tv_ros_view1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ProgressBar
android:id="#+id/pb_ros_bar1"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:visibility="invisible" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_ros_layout1" >
<TableLayout
android:id="#+id/tl_rostertable"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:stretchColumns="2" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="#string/team" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="#string/pos" />
<TextView
android:layout_height="wrap_content"
android:padding="3dp"
android:text="#string/name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="3dp"
android:text="#string/score" />
</TableRow>
</TableLayout>
</ScrollView>
</RelativeLayout>
and my oncreate method
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.roster);
final Bundle extra = getIntent().getExtras();
position = extra.getInt("pos");
int id = de.damps.fantasy.HomeActivity.ID[position];
url = de.damps.fantasy.HomeActivity.URL + "/roster/2011/" + id;
tbl = (TableLayout) findViewById(R.id.tl_rostertable);
team = (TextView) findViewById(R.id.tv_ros_view1);
String s= de.damps.fantasy.HomeActivity.TEAMS[position];
team.setText(s);
new GetRoster().execute(url);
}
the tablelayout is found without any problmes. but the textview is null.
i already cleaned the project but it didnt solve the problem
would be nice if someone can help me
You have a typo:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:id="#+id/tv_ros_view1"
android:textAppearance="?android:attr/textAppearanceMedium" />
(android:text instead of android:id)
You wrote
android:text="#+id/tv_ros_view1"
instead of
android:id
you create ID your text view like this android:id="#+id/tv_ros_view1" in place of android:text="#+id/tv_ros_view1" this is use full to you.
In you xml layout:
android:text="#+id/tv_ros_view1"
should be:
android:id="#+id/tv_ros_view1"
the text attribute is used to tell textview what text to show.
In your faulty/first text view you have written like this:
android:text="#+id/tv_ros_view1"
Just replace this with this:
android:id="#+id/tv_ros_view1"
This is how you have to assign id to a view(TextView).
here is the xml code i used
but no use even if try increasing the minheight....
please help
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Here you put the rest of your current view-->
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:text="ID:"
android:textSize="15dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/cid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="Name:"
android:textSize="15dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/con"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="Posted By:"
android:textSize="15dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/poby"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="Posted Time:"
android:textSize="15dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/poti"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="Annotation ID:"
android:textSize="15dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/aid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="Comment:"
android:textSize="15dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/comm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="Image-path:"
android:textSize="15dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/imgpath"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="Solutions:"
android:textSize="15dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ListView
android:id="#+id/listviewid"
android:layout_marginBottom="10dp"
android:paddingBottom="10dp"
android:minHeight="1000dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
</ScrollView>
The java code related to it is:
if(s8.length()!=0){
String[] sidarray = s8.split("#");
String[] replyarray = s9.split("#");
String[] replybyarray = s10.split("#");
for(int p=0;p<sidarray.length;p++)
{
if(solutionsList!=null){
solutionsList.add("\nSolutionsID:" + sidarray[p] );
solutionsList.add("\nReply:" + replyarray[p]);
solutionsList.add("\nReply-by:" + replybyarray[p]);
}}
solutionlist=(ListView)findViewById(R.id.listviewid);
solutionadapter = new ArrayAdapter<String>(this, R.layout.solutiondisplay, solutionsList);
solutionlist.setAdapter(solutionadapter);
}
Here is my source code.................
It looks to me that you simply do not have enough space. The reason lies in the fact that you selected some layout that is bound to screen limits (LinearLayout, RelativeLayout ...). You have lots of things on one screen. In order to avoid this issue, use ScrollView as a root, then LinearLayout, and then you can put lots of layout elements in this LinearLayout (span several screens length).
Have you tried removing these lines?:
android:layout_marginBottom="10dp"
android:paddingBottom="10dp"
It would help if you included your entire layout xml.
Have you tried setting Layout weight = 1?
You have to set the height of the scrollview to wrap_content
I'm not sure including a ListView inside a ScrollView is a good idea.
You would better use ListView's header views feature to integrate all of your "Problem" data in fixed views on top of the set of solutions.
When ListView is used inside scrollview at rutime the listview colapses to show just one item. Hence you need to adjust the listview height in your java code.
use the LayoutParams property to set height and width for listview.