I have an API and there is a value of broadcast and the options are public, private, logged in and unlisted. I want a radiobutton to be selected itself as public if broadcast is public.
This is my XML code:
<TextView
android:textColor="#060606"
android:layout_marginTop="10dp"
android:textSize="15sp"
android:text="Broadcast Options"
android:id="#+id/broadcast_head"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioGroup
android:orientation="vertical"
android:id="#+id/radio_group_broadcast"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:textSize="16sp"
android:text="Public"
android:id="#+id/radio_button_public"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:textSize="16sp"
android:text="Private"
android:id="#+id/radio_button_private"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:textSize="16sp"
android:text="Unlisted"
android:id="#+id/radio_button_unlisted"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:textSize="16sp"
android:text="Logged Only"
android:id="#+id/radio_button_logged_only"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
</TextView>
and this is my Java code;
I don't know whether this code is correct or not.
rbPub = (RadioButton)findViewById(R.id.radio_button_public);
rbPri = (RadioButton)findViewById(R.id.radio_button_private);
rbUnl = (RadioButton)findViewById(R.id.radio_button_unlisted);
rbOnl = (RadioButton)findViewById(R.id.radio_button_logged_only);
radioGroup1 = (RadioGroup) findViewById(R.id.radio_group_broadcast);
VideoDetail videoDetailBroadcast = null; //this is the problem, can't fix(null)
if (videoDetailBroadcast.isPublic()) {
rbPub.setChecked(true);
}
else if (videoDetailBroadcast.isPrivate()) {
rbPri.setChecked(true);
}
else if (videoDetailBroadcast.isUnlisted()) {
rbUnl.setChecked(true);
}
else if (videoDetailBroadcast.isLoggedOnly()) {
rbOnl.setChecked(true);
}
You should should initialize videoDetailBroadcast that way : VideoDetail videoDetailBroadcast = new VideoDetail()
I have a little question here about android development.
I already searched on internet, but i still can't find the solution.
I want to getText() from a view, but it just returns an empty ("") string.
Here's my .java code:
public void kotakCentang(View view)
{
RelativeLayout vwParentRow = (RelativeLayout)view.getParent();
TextView id_test = (TextView)vwParentRow.getChildAt(0);
TextView nama_test = (TextView)vwParentRow.getChildAt(1);
tugas_status = (TextView)vwParentRow.getChildAt(5);
tanggalKasih = (EditText)vwParentRow.getChildAt(6);
tanggalKumpul = (EditText)vwParentRow.getChildAt(8);
waktuKasih = (EditText)vwParentRow.getChildAt(7);
waktuKumpul = (EditText)vwParentRow.getChildAt(9);
tugasKompleksitas = (EditText)vwParentRow.getChildAt(10);
Tugas tugas = new Tugas();
TugasRepo tugass = new TugasRepo(this);
tugas.nama = nama_test.getText().toString();
tugas.waktuDikasih = waktuKasih.getText().toString();
tugas.waktuDikumpul = waktuKumpul.getText().toString();
tugas.tanggalDikasih = tanggalKasih.getText().toString();
tugas.tanggalDikumpul = tanggalKumpul.getText().toString();
tugas.kompleksitas=Integer.parseInt(tugasKompleksitas.getText().toString());
tugasKompleksitas.getText().toString();
}
The getText() which returns empty string is just the tugas.waktuDikasih, and tugas.waktuDikumpul .
Thank you for your help.
----- UPDATE XML ----
here's my xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tugas_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/judul_tugas"
android:visibility="gone"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="judul tugas"
android:id="#+id/tugas_judul"
android:textSize="20dp"
android:layout_marginStart="60dp"
android:layout_marginTop="17dp"
android:layout_below="#+id/tugas_id"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/status_kerja"
android:checked="false"
android:textSize="10dp"
android:layout_alignTop="#+id/tugas_judul"
android:layout_toStartOf="#+id/button"
android:onClick="kotakCentang"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorPrimaryDark"
android:layout_below="#+id/status_kerja"
android:layout_alignParentStart="true"
android:layout_marginTop="19dp"
android:id="#+id/textView2">
</View>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Detil"
android:id="#+id/button"
android:layout_alignParentEnd="true"
android:textSize="10sp"
android:layout_marginEnd="16dp"
android:layout_alignTop="#+id/status_kerja"
android:layout_above="#+id/textView2"
android:onClick="detilTugas"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"
android:id="#+id/status_tugas"
android:layout_alignBottom="#+id/tugas_judul"
android:layout_toEndOf="#+id/tugas_id" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:id="#+id/tanggal_diberikan"
android:text="Tanggal Diberikan"
android:textColor="#000000"
android:visibility="gone"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:id="#+id/waktu_diberikan"
android:layout_below="#+id/tanggal_diberikan"
android:layout_alignStart="#+id/tanggal_diberikan"
android:layout_alignEnd="#+id/tanggal_diberikan"
android:text="Waktu diberikan"
android:textColor="#000000"
android:visibility="gone"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:id="#+id/tanggal_kumpul"
android:text="Tanggal dikumpulkan"
android:layout_below="#+id/tugas_judul"
android:layout_alignStart="#+id/waktu_diberikan"
android:layout_alignEnd="#+id/waktu_diberikan"
android:textColor="#000000"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:id="#+id/waktu_dikumpulkan"
android:layout_below="#+id/tanggal_kumpul"
android:layout_alignStart="#+id/tanggal_kumpul"
android:layout_alignEnd="#+id/tanggal_kumpul"
android:text="Waktu dikumpulkan"
android:textColor="#000000"
android:visibility="gone"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:id="#+id/isi_kompleksitas"
android:text="Kompleksitas"
android:textColor="#000000"
android:editable="false"
android:visibility="gone"/>
<!--<TextView-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="id_tugas"-->
<!--android:id="#+id/tugas_id"-->
<!--android:layout_alignBottom="#+id/status_kerja"-->
<!--android:layout_alignEnd="#+id/tugas_judul"-->
<!--android:layout_marginEnd="117dp" />-->
</RelativeLayout>
I'm trying to set to all of the views that are in the widget a click listener that should open an activity upon a click, but for now seems that its not working. Can someone tell me what am I doing wrong?
Here is my code:
public class AthanWidget extends AppWidgetProvider {
private SharedPreferences prefs;
private boolean PAID = false;
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
final int N = appWidgetIds.length;
prefs = context.getSharedPreferences(context.getPackageName(),
Context.MODE_PRIVATE);
SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy");
String currentDateandTime = sdf.format(new Date());
PAID = prefs.getBoolean(Constants.ITEM_PURCHASED, false);
// TODO CHECK IF IMAGE IS FROM SD OR A RESOURCE IS
// Perform this loop procedure for each App Widget that belongs to this
// provider
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch ExampleActivity
Intent intent;
if (!PAID) {
intent = new Intent(context, RemoveAds.class);
} else {
intent = new Intent(context, Main.class);
}
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
views.setOnClickPendingIntent(appWidgetId, pendingIntent);
views.setTextViewText(R.id.widget_date_title, currentDateandTime);
views.setTextViewText(R.id.widget_arabic_date_title, arabianDate());
displayPrayerTimes(views);
if (prefs.getInt(Constants.BG_ID_PREFS, 1) < 0) {
Bitmap myBitmap = BitmapFactory.decodeFile(prefs.getString(
Constants.BG_SD_PATH, ""));
views.setImageViewBitmap(R.id.widget_bg, myBitmap);
} else {
views.setImageViewResource(R.id.widget_bg,
prefs.getInt(Constants.BG_ID_PREFS, R.drawable.bg24));
}
// Tell the AppWidgetManager to perform an update on the current app
// widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
private void displayPrayerTimes(RemoteViews views) {
if (PAID) {
views.setTextViewText(
R.id.widget_fajr,
prefs.getString(Constants.FARJ_ID + "w", "DISABLED").split(
",")[0]);
views.setTextViewText(R.id.widget_dhurh,
prefs.getString(Constants.DHUHR_ID + "w", "DISABLED")
.split(",")[0]);
views.setTextViewText(
R.id.widget_isha,
prefs.getString(Constants.ISHA_ID + "w", "DISABLED").split(
",")[0]);
views.setTextViewText(
R.id.widget_asr,
prefs.getString(Constants.ASR_ID + "w", "DISABLED").split(
",")[0]);
}
views.setTextViewText(
R.id.widget_shorrok,
prefs.getString(Constants.SHORROK_ID + "w", "DISABLED").split(
",")[0]);
views.setTextViewText(
R.id.widget_maghrib,
prefs.getString(Constants.MAGHRIB_ID + "w", "DISABLED").split(
",")[0]);
}
private String arabianDate() {
Date date = new Date(); // هنا التاريخ الصليبي
Calendar cl = Calendar.getInstance();
cl.setTime(date);
final String[] iMonthNames = { "Muharram", "Safar", "Rabi'ul Awwal",
"Rabi'ul Akhir", "Jumadal Ula", "Jumadal Akhira", "Rajab",
"Sha'ban", "Ramadan", "Shawwal", "Dhul Qa'ada", "Dhul Hijja" };
Chronology iso = ISOChronology.getInstanceUTC();
Chronology hijri = IslamicChronology.getInstanceUTC();
LocalDate todayIso = new LocalDate(cl.get(Calendar.YEAR),
cl.get(Calendar.MONTH) + 1, cl.get(Calendar.DAY_OF_MONTH), iso);
LocalDate todayHijri = new LocalDate(todayIso.toDateTimeAtStartOfDay(),
hijri);
return todayHijri.getDayOfMonth() + " "
+ iMonthNames[todayHijri.getMonthOfYear()] + " "
+ todayHijri.getYear();
}
}
and my widget layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/widget_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha=".85"
android:contentDescription="#string/app_name"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/widget_toptext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:paddingTop="10dp"
android:text="#string/widget_title"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/widget_date_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/widget_toptext"
android:layout_centerHorizontal="true"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/widget_arabic_date_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/widget_date_title"
android:layout_centerHorizontal="true"
android:textColor="#android:color/white"
android:textSize="15sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#80000000"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_sun_up"
android:drawableRight="#drawable/w_pray_sun_up"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_fajr"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_fajr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fajr"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<!-- delete this -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_sun_up"
android:drawableRight="#drawable/w_pray_sun_up"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_shorok"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_shorrok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/shorrok"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_dhurh"
android:drawableRight="#drawable/w_pray_dhurh"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_dhuhr"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_dhurh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dhuhr"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_asr"
android:drawableRight="#drawable/w_pray_asr"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_asr"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_asr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/asr"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_maghreb"
android:drawableRight="#drawable/w_pray_maghreb"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_magrib"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_maghrib"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/maghrib"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_moon"
android:drawableRight="#drawable/w_pray_moon"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_isha"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_isha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/isha_a"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<!-- end of deletion -->
</LinearLayout>
</RelativeLayout>
here you are setting click pending intent for the appwidgetId, but that should be view id.
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
views.setOnClickPendingIntent(appWidgetId, pendingIntent);
like:
if the id of a Button is R.id.button1. which is in widget layout if you want to set click listener to that button. then that should be like this :
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
views.setOnClickPendingIntent(R.id.button1, pendingIntent);
I'm trying to generate form elements from a template when the user clicks on a button. I created the template and the container layout for the new forms with XML. Its successfully generating the first form where I'm telling it to generate, but when I try to generate more forms beyond the first one its giving me an error: "the specified child already has a parent. You must call removeView() on the child's first parent". Any clue as to what I should do so as to generate more than one element? I've tried changing the id of the newly created forms but that's giving me a null pointer exception and crashing. Thank you.
public class MakeQuestion extends Activity implements OnClickListener{
private static final int MY_BUTTON = 9000;
int templateID = 1;
Button b;
Button target;
View insertPoint;
Button testTemplate;
View v1;
RelativeLayout.LayoutParams templateParams;
LayoutInflater vi;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.make_question);
Initialize();
}
public void Initialize(){
//button for adding new forms
b = (Button) findViewById(R.id.makeLayoutButton);
b.setOnClickListener(this);
//get the template form to be duplicated
vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v1 = vi.inflate(R.layout.form_template, null);
//set the params for the element that will have dynamically generated content below it
templateParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//container where forms will be contained in
insertPoint = findViewById(R.id.questionsContainer);
//view where new form will go below
View belowContainer = findViewById(R.id.questionTemplateFake);
//set id for layout params of view
belowContainer.setId(1);
//set rule for new forms to go below view 'belowContainer'
templateParams.addRule(RelativeLayout.BELOW, belowContainer.getId());
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.makeLayoutButton:
v1 = vi.inflate(R.layout.form_template, null);
//add view to the insertPoint
((LinearLayout) insertPoint).addView(v1);
break;
}
}
}
Added forms should go in "questionsContainer" which is set to be below "questionTemplateFake"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/grey_background" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#8B459A"
android:baselineAligned="false"
android:clipToPadding="false" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/logo_small" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:src="#drawable/settings" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:src="#drawable/search" />
</RelativeLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/relativeLayout1" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relative12"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="WHAT IS YOUR QUESTION?" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/save_button"
android:layout_alignBottom="#+id/save_button"
android:layout_alignRight="#+id/textView1"
android:text="ADD PICTURE OR VIDEO"
android:textSize="10sp" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="14dp"
android:background="#drawable/textlines"
android:ems="10"
android:hint="50 WORDS OR LESS"
android:inputType="textMultiLine"
android:paddingLeft="5dp" />
<Button
android:id="#+id/save_button"
android:layout_width="75dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_below="#+id/editText1"
android:layout_marginTop="16dp"
android:background="#drawable/purplebutton"
android:text="BROWSE"
android:textColor="#drawable/button_text_color"
android:textSize="10sp" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/save_button"
android:layout_marginTop="25dp"
android:text="CREATE AN ANSWER" />
<RelativeLayout
android:id="#+id/questionTemplateFake"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/TextView01" >
<Button
android:id="#+id/Button02eew"
android:layout_width="75dp"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/purplebutton"
android:text="BROWSE"
android:textColor="#drawable/button_text_color"
android:textSize="10sp" />
<EditText
android:id="#+id/EditText02"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_above="#+id/Button02"
android:layout_alignParentLeft="true"
android:background="#drawable/textlines"
android:ems="10"
android:hint="50 WORDS OR LESS"
android:inputType="textMultiLine"
android:paddingLeft="5dp" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginRight="19dp"
android:layout_toLeftOf="#+id/Button02"
android:text="ADD PICTURE OR VIDEO"
android:textSize="10sp" />
</RelativeLayout>
<LinearLayout
android:id="#+id/questionsContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginTop="20dp"
android:orientation="vertical"
android:layout_below="#+id/questionTemplateFake"
>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/makeLayoutButton"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_below="#+id/scrollView1"
android:layout_marginRight="17dp"
android:layout_marginTop="79dp"
android:background="#drawable/purplebutton"
android:text="MORE OPTIONS"
android:textColor="#drawable/button_text_color"
android:textSize="10sp" />
</RelativeLayout>
You are trying to add the same instance over and over again. Thus the message that "specific child already exists". You would have to create a new template layout instance with different ID (I suppose) and then try to add it in.
So rather than:
((RelativeLayout) insertPoint).addView(v1, templateParams);
and adding v1 again. Create a new instance
v1 = vi.inflate(R.layout.form_template, null);
set the id for good measures and then add it again in view.
I suppose you don't need to set the id, but you can read more about how id's work here
I get no compilation errors or even significant warnings, yet when I run the program, it force closes and the log tells me there's some kind of error on a line. It succeeded once, but I don't know how or when.
onClick method:
public TextView equation;
public TextView answer11;
public TextView answer12;
public TextView or1;
public TextView or2;
public void SolveOnClick(View view){
EditText a = (EditText)findViewById(R.id.aValue);
EditText b = (EditText)findViewById(R.id.bValue); //screws up somewhere here
EditText c = (EditText)findViewById(R.id.cValue);
equation = (TextView)findViewById(R.id.equationText);
answer11 = (TextView)findViewById(R.id.answer1);
answer12 = (TextView)findViewById(R.id.answer2);
or1 = (TextView)findViewById(R.id.or1);
or2 = (TextView)findViewById(R.id.or2);
double A = Double.parseDouble(a.getText().toString());
double B = Double.parseDouble(b.getText().toString());
double C = Double.parseDouble(c.getText().toString());
Formula(A,B,C);
}
My main graphical layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:onClick="SolveOnClick"
android:text="#string/solveButtonText" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/quadFormText"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView4"
android:layout_marginTop="17dp"
android:layout_toLeftOf="#+id/textView4"
android:text="#string/A"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/aValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_alignTop="#+id/textView1"
android:layout_marginLeft="15dp"
android:ems="10"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/bValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/aValue"
android:layout_below="#+id/aValue"
android:layout_marginTop="14dp"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/cValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/bValue"
android:layout_below="#+id/bValue"
android:layout_marginTop="14dp"
android:ems="10"
android:inputType="numberDecimal" />
<TextView
android:id="#+id/answer1Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="#string/equals1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/answer2Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/answer1Text"
android:layout_below="#+id/answer1Text"
android:layout_marginTop="88dp"
android:text="#string/equals2"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/answer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/answer1Text"
android:layout_toRightOf="#+id/answer1Text"
android:text="#string/answer11"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/or1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/answer1Text"
android:layout_below="#+id/answer1Text"
android:layout_marginTop="25dp"
android:text="#string/or1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/answer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/answer2Text"
android:layout_toRightOf="#+id/answer1Text"
android:text="#string/answer12"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/or2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/answer2Text"
android:layout_below="#+id/answer2Text"
android:layout_marginTop="24dp"
android:text="#string/or2"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/equationText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/cValue"
android:layout_marginTop="14dp"
android:text="#string/equation"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/cValue"
android:layout_toLeftOf="#+id/textView4"
android:text="#string/C"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/bValue"
android:layout_alignLeft="#+id/textView3"
android:text="#string/B"
android:textAppearance="?android:attr/textAppearanceLarge" />
onCreate method:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
One of the logs when the program fails:
04-26 20:39:33.174: E/AndroidRuntime(16092): Caused by: java.lang.ClassCastException: android.widget.TextView
04-26 20:39:33.174: E/AndroidRuntime(16092): at calc.ulater.QuadCalcActivity.SolveOnClick(QuadCalcActivity.java:31)
I believe this has something to do with the decimal text boxes. The program worked well before I made them only take decimal numbers, but it also worked a time or two after. I'd rather not show the rest of my code, unless you guys are sure the problem lies there.
If this is the line that's screwing up:
EditText b = (EditText)findViewById(R.id.bValue);
Then its saying you're trying to cast a TextView to an EditText.
What's line 31? That one?
EditText a = (EditText)findViewById(R.id.aValue);
EditText b = (EditText)findViewById(R.id.bValue); //screws up somewhere here
EditText c = (EditText)findViewById(R.id.cValue);
equation = (TextView)findViewById(R.id.equationText);
answer11 = (TextView)findViewById(R.id.answer1);
answer12 = (TextView)findViewById(R.id.answer2);
or1 = (TextView)findViewById(R.id.or1);
or2 = (TextView)findViewById(R.id.or2);
all the initialization must be done in onCreate() and not in the constructor
Updated::
EditText a = (EditText)view.findViewById(R.id.aValue);
EditText b = (EditText)view.findViewById(R.id.bValue); //screws up somewhere here
EditText c = (EditText)view.findViewById(R.id.cValue);
equation = (TextView)view.findViewById(R.id.equationText);
answer11 = (TextView)view.findViewById(R.id.answer1);
answer12 = (TextView)view.findViewById(R.id.answer2);
or1 = (TextView)view.findViewById(R.id.or1);
or2 = (TextView)view.findViewById(R.id.or2);
if view is your parent view