Issue with Android Check Box Visibility? - android

In my application I have two Check boxes one is PayByCredit and one more is PaybySMS For Both the check boxes are not visible what was the issue ? To display the Check box i gave code like this android:visibility="visible" but still no use . Can any one help me out of this please ?
My XML Code is :
<?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/homescreeen2"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/toplayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:fontFamily="Optima"
android:gravity="center"
android:text="#string/palmtreeimg"
android:textColor="#ffffff"
android:textStyle="bold" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="16dp"
android:layout_marginTop="4dp"
android:background="#null"
android:contentDescription="#string/backbt"
android:src="#drawable/backbt" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toplayout"
android:paddingBottom="10dp"
android:scrollbars="none" >
<RelativeLayout
android:id="#+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_marginLeft="10dp"
android:fontFamily="#+fonts/MontereyFLF"
android:text="#string/realname"
android:textColor="#ff0000" />
<LinearLayout
android:id="#+id/mainlayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_margin="15dp"
android:background="#drawable/layout_bg"
android:orientation="vertical"
android:paddingBottom="5dp" >
<LinearLayout
android:id="#+id/getaplague"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal" >
<include
android:id="#+id/cmpndbtnName"
android:layout_gravity="center"
android:layout_margin="10dp"
android:layout_marginStart="#+id/treesplanted"
layout="#layout/compound_button" />
</LinearLayout>
<View
android:id="#+id/border"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88"
android:visibility="gone" />
<LinearLayout
android:id="#+id/entername"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:alpha="0.8"
android:orientation="horizontal"
android:visibility="gone" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name"
android:textColor="#ff0000" />
</LinearLayout>
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="#null"
android:contentDescription="#string/btn_save"
android:src="#drawable/savesmall"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/mainlayout2"
android:layout_margin="15dp"
android:background="#drawable/layout_bg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal" >
<include
android:id="#+id/cmpndbtnfrnname"
android:layout_marginStart="#+id/treesplanted"
layout="#layout/compound_buttonfrnname" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88" />
<LinearLayout
android:id="#+id/enterfrnname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:alpha="0.8"
android:orientation="horizontal"
android:visibility="gone" >
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88" />
<LinearLayout
android:id="#+id/enterfrnmailid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:orientation="horizontal"
android:visibility="gone" >
<EditText
android:id="#+id/editTextfrnmail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#null"
android:hint="#string/enterfrnmailid"
android:inputType="text"
android:textSize="12sp"
android:paddingLeft="5dp"
android:textColor="#000000"
android:textColorHint="#999898" >
</EditText>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88" />
<LinearLayout
android:id="#+id/enterfrnphoneno"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:orientation="horizontal"
android:visibility="gone" >
</EditText>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88" />
<View
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1"
android:layout_margin="15dp"
android:layout="#+id/amntlayout"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="#+id/mainlayoutpay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout2"
android:layout_margin="15dp"
android:background="#drawable/layout_bg"
android:orientation="vertical"
android:paddingBottom="5dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/txpaycredit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:fontFamily="Optima"
android:text="#string/paycredit"
android:textColor="#ff0000" />
<TextView
android:id="#+id/dum"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:fontFamily="Optima"
android:text=""
/>
<CheckBox
android:id="#+id/paycredit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#null"
android:visibility="visible"
android:textColor="#000000" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginTop="0dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/paybysms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/paysms"
android:textColor="#ff0000" />
<TextView
android:id="#+id/dummy"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text=""
android:textColor="#ff0000" />
<CheckBox
android:id="#+id/paysms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="#null"
android:visibility="visible"
android:layout_marginLeft="10dp"
android:fontFamily="#+fonts/MontereyFLF"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
And My .java Code is here:
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation;
public class PalmTreeActivity extends Activity {
//Used for payment
double currencyAftconversion;
public String treeValue;
private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_NO_NETWORK;
private static final String CONFIG_CLIENT_ID = "AWg-FRC9GM1CdolC2XnKnYBEgpi01jDlKi6IEXFcEnu4QIfer6cVE0iH9YNI";
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
.merchantName("Isaaf")
.merchantPrivacyPolicyUri(
Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(
Uri.parse("https://www.example.com/legal"));
String AmountOfTree = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
String price = null;
//call currency conversion method
new DownloadCurrencyConversion().execute();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_palmtree);
ImageButton btnNext = (ImageButton) findViewById(R.id.imageButton2);
ImageButton btBack = (ImageButton) findViewById(R.id.imageButton1);
final CheckBox paybycard = (CheckBox) findViewById(R.id.paycredit);
//paycredit.setVisibility(View.VISIBLE);
final CheckBox paybysms = (CheckBox) findViewById(R.id.paysms);
final CompoundButton switchrealname= (CompoundButton) findViewById(R.id.enabled);
final CompoundButton switchfrnname=(CompoundButton) findViewById(R.id.enabledfrnname);
final LinearLayout friendName=(LinearLayout) findViewById(R.id.enterfrnname);
final LinearLayout friendMailId=(LinearLayout) findViewById(R.id.enterfrnmailid);
final LinearLayout friendPhoneno=(LinearLayout) findViewById(R.id.enterfrnphoneno);
final LinearLayout Name=(LinearLayout) findViewById(R.id.entername);
final EditText username=(EditText)findViewById(R.id.editText1);
final EditText frnName=(EditText)findViewById(R.id.editTextfrnName);
final EditText frnmail=(EditText)findViewById(R.id.editTextfrnmail);
final EditText frnphoneno=(EditText)findViewById(R.id.editTextfrnphoneno);
// final ImageButton savename=(ImageButton)findViewById(R.id.imageButton3);
// final ImageButton savefrnname=(ImageButton) findViewById(R.id.imageButton4);
if (getIntent().getExtras() != null && !TextUtils.isEmpty("price"))
{
price = getIntent().getExtras().getString("price");
TextView amount = (TextView) findViewById(R.id.amountvalue);
amount.setGravity(Gravity.CENTER);
String Pricedouble = price.substring(price.indexOf('('));
Pricedouble = Pricedouble.replaceAll("\\D+", "");
amount.setText(Pricedouble.toString()); // Get Number
//EditText amounttext = (EditText) findViewById(R.id.editText1);
//amounttext.setText(Pricedouble);
AmountOfTree = Pricedouble.toString();
Intent intentActivity = new Intent(this, PayPalService.class);
intentActivity.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startService(intentActivity);
}
//button next click
btnNext.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
if (paybycard.isChecked()) {
Bundle bundle=new Bundle();
if(!TextUtils.isEmpty(username.getText().toString()))
bundle.putString("name", username.getText().toString());
if(!TextUtils.isEmpty(frnName.getText().toString()))
bundle.putString("frnname", frnName.getText().toString());
if(!TextUtils.isEmpty(frnmail.getText().toString()))
bundle.putString("frnmailid", frnmail.getText().toString());
if(!TextUtils.isEmpty(frnphoneno.getText().toString()))
bundle.putString("frnphoneno", frnphoneno.getText().toString());
PayPalPayment payment = new PayPalPayment(new BigDecimal(
currencyAftconversion), "USD", "Tree",
PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(getApplicationContext(),
PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);
startActivityForResult(intent, 0);
}
else if(paybysms.isChecked())
{
StringBuilder tmp=new StringBuilder();
if(!TextUtils.isEmpty(username.getText().toString()));
tmp.append("User details are :"+"\n");
tmp.append("UserName is:"+username.getText().toString());
tmp.append("\n");
//tmp.append(username.getText().toString());
if(!TextUtils.isEmpty(frnName.getText().toString()))
tmp.append("Friend Name is:"+frnName.getText().toString());
tmp.append("\n");
if(!TextUtils.isEmpty(frnmail.getText().toString()))
tmp.append("Friend Email id is:"+frnmail.getText().toString());
tmp.append("\n");
if(!TextUtils.isEmpty(frnphoneno.getText().toString()))
tmp.append("Friend phone number is:"+frnphoneno.getText().toString());
PayByCash senddetailstoadmin=new PayByCash();
if(!TextUtils.isEmpty(tmp.toString()))
senddetailstoadmin.execute(tmp.toString());
Toast paymessage=Toast.makeText(getApplicationContext(), "Our customer care people will contact you shortly..!!!!", Toast.LENGTH_SHORT);
paymessage.show();
Intent intent=new Intent( getApplicationContext(),PaycashthanksActivity.class);
startActivity(intent);
}
else
{
Toast paywarning=Toast.makeText(getApplicationContext(), "Please pay using card or pay by cash", Toast.LENGTH_SHORT);
paywarning.show();
}
}
});
btBack.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(),
FindmarkedLocationActivity.class);
startActivity(intent);
}
});
//switchrealname toggle
switchrealname.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked)
{
if(switchrealname.isChecked())
{
Name.setVisibility(View.VISIBLE); //Set the layout visible
// savename.setVisibility(View.VISIBLE);
}
else
{
Name.setVisibility(View.GONE);
// savename.setVisibility(View.GONE);
}
}
});
//Switch friend details switch toggle checked event
switchfrnname.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked)
{
if(switchfrnname.isChecked())
{
//Set the layout visible
friendName.setVisibility(View.VISIBLE);
friendMailId.setVisibility(View.VISIBLE);
friendPhoneno.setVisibility(View.VISIBLE);
// savefrnname.setVisibility(View.VISIBLE);
}
else
{
//Set the layout visible
friendName.setVisibility(View.GONE);
friendMailId.setVisibility(View.GONE);
friendPhoneno.setVisibility(View.GONE);
// savefrnname.setVisibility(View.GONE);
}
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data
.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Log.i("paymentExample", confirm.toJSONObject().toString(4));
// TODO: send 'confirm' to your server for verification or
// consent
// completion.
// see
// https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
// for more details.
Intent intent = new Intent(getApplicationContext(),
CongratulationActivity.class);
startActivity(intent);
}
catch (JSONException e)
{
sorryActivity();
Log.e("paymentExample",
"an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("paymentExample", "The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID)
{
sorryActivity();
Log.i("paymentExample",
"An invalid Payment was submitted. Please see the docs.");
}
}
//back button click
public String getJson(String url) throws ClientProtocolException,
IOException {
StringBuilder build = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
content));
String con;
while ((con = reader.readLine()) != null) {
build.append(con);
}
return build.toString();
}
public void sorryActivity()
{
Intent intent = new Intent(getApplicationContext(),
SorryPaymentActivity.class);
startActivity(intent);
}
#Override
public void onDestroy() {
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
public class DownloadCurrencyConversion extends
AsyncTask<Void, Integer, String> {
#Override
protected String doInBackground(Void... params) {
String s;
String theResult = "";
try {
s = getJson("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22BHDUSD%22%29&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");
JSONObject jObj;
jObj = new JSONObject(s);
theResult = jObj.getJSONObject("query")
.getJSONObject("results").getJSONObject("rate")
.getString("Rate");
System.out.println(theResult);
}
catch (JSONException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return theResult;
}
#Override
protected void onPostExecute(String theResult) {
super.onPostExecute(theResult);
System.out.println("theResult:" + theResult);
if (!TextUtils.isEmpty(theResult) &&!TextUtils.isEmpty(AmountOfTree) )
currencyAftconversion = (Double.parseDouble(AmountOfTree))
* (Double.parseDouble(theResult));
}
}
}
Please help me out of this issue ??

Remove android:background="#null"

In your code try this:
paybycard.setVisibility(0);
paybysms.setVisibility(0);
Hope this help, thanks

These layouts work for me:
<CheckBox
android:id="#+id/paysms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#null"
android:visibility="visible"
android:text="pay with sms"
android:layout_marginLeft="10dp"
android:textColor="#000000" />
<CheckBox
android:id="#+id/paycredit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/paysms"
android:background="#null"
android:text="pay credit"
android:visibility="visible"
android:layout_marginLeft="10dp"
android:textColor="#000000" />

Related

NullPointerException on setContentView

I am having two layouts in same xml file and I have kept one layout as hidden and want to show this hidden layout on button click. But when I try to load this activity, it gives me exception on setContentView.
Here is my layout:
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f0f5f9"
tools:context="com.techsof.demoapp.Auftrag">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading_text"
android:textColor="#fff"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:id="#+id/form_heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/form_heading"
android:textColor="#4C4C4C"
android:textSize="20sp" />
<LinearLayout
android:id="#+id/form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form_heading"
android:layout_margin="10dp"
android:orientation="vertical">
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/name"
android:padding="10dp" />
<EditText
android:id="#+id/mail"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/mail_"
android:padding="10dp" />
<EditText
android:id="#+id/tel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Tel/Mobilnummer *"
android:padding="10dp" />
<EditText
android:id="#+id/aus"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Ausgangssprache *"
android:padding="10dp" />
<EditText
android:id="#+id/ziel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Zielsprache *"
android:padding="10dp" />
<EditText
android:id="#+id/nach"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:gravity="start"
android:hint="Nachricht *"
android:padding="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc1"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc2"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc3"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/footer_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form"
android:layout_margin="10dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/footer_text"
android:textColor="#4C4C4C"
android:textSize="12sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/footer_text"
android:layout_marginLeft="10dp"
android:buttonTint="#0F84AA"
android:fontFamily="serif"
android:text="#string/checkbox_text"
android:textColor="#4c4c4c"
android:textStyle="bold" />
<Button
android:id="#+id/sendBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/checkbox"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:text="#string/button_text"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/dialogBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4c4c4c"
android:padding="10dp"
android:text="#string/complete_action_using"
android:textColor="#fff"
android:textSize="20sp" />
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/cameraOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_camera_alt_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/camera"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/phoneStorageOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_folder_open_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/phone_storage"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:gravity="end"
android:padding="10dp">
<Button
android:id="#+id/cancelBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:backgroundTint="#0F84AA"
android:text="#string/cancel"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#f0f5f9"
app:headerLayout="#layout/nav_header"
app:itemIconTint="#000"
app:itemTextColor="#000"
app:menu="#menu/menu_main" />
</androidx.drawerlayout.widget.DrawerLayout>
and here is my Java Code:
public class Auftrag extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private DrawerLayout eDrawerlayout;
private ActionBarDrawerToggle eToggle;
NavigationView nav;
private LinearLayout camera, phone, dialog;
private Button attachBtn1, attachBtn2, attachBtn3, submitButton, cancel;
private TextView file1, file2, file3;
private EditText name, mail, telephone, ausgang, ziels, nachricht;
private ArrayList<Uri> attachments = new ArrayList<>();
private CheckBox agreement;
private String textfield;
public static final int REQUEST_SELECT_FILE = 100;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
initUI();
eToggle = new ActionBarDrawerToggle(this, eDrawerlayout, R.string.Open, R.string.Close);
eDrawerlayout.addDrawerListener(eToggle);
eToggle.syncState();
nav.setNavigationItemSelectedListener(this);
androidx.appcompat.app.ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.parseColor("#f0f5f9")));
eDrawerlayout.setDrawerListener(eToggle);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
}
private void initUI() {
nav = findViewById(R.id.navigation1);
eDrawerlayout = findViewById(R.id.drawer1);
name = findViewById(R.id.name);
mail = findViewById(R.id.mail);
telephone = findViewById(R.id.tel);
ausgang = findViewById(R.id.aus);
ziels = findViewById(R.id.ziel);
nachricht = findViewById(R.id.nach);
submitButton = findViewById(R.id.sendBtn);
attachBtn1 = findViewById(R.id.attach_btn1);
attachBtn2 = findViewById(R.id.attach_btn2);
attachBtn3 = findViewById(R.id.attach_btn3);
/*dialog = findViewById(R.id.dialogBox);
camera = findViewById(R.id.cameraOption);
camera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openCamera();
}
});
phone = findViewById(R.id.phoneStorageOption);
phone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openFileChooser();
}
});
cancel = findViewById(R.id.cancelBtn);
cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.setVisibility(View.GONE);
}
});*/
file1 = findViewById(R.id.doc1);
file2 = findViewById(R.id.doc2);
file3 = findViewById(R.id.doc3);
attachBtn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textfield = "btn1";
chooseOption();
/*dialog.setVisibility(View.VISIBLE);*/
}
});
attachBtn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textfield = "btn2";
/*dialog.setVisibility(View.VISIBLE);*/
}
});
attachBtn3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textfield = "btn3";
/*dialog.setVisibility(View.VISIBLE);*/
}
});
agreement = findViewById(R.id.checkbox);
submitButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
sendData();
}
});
}
private void chooseOption() {
final CharSequence[] options = {"Camera", "Phone", "Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Add file using: ");
builder.setItems(options, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int item) {
if (options[item].equals("Camera")) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, 1);
} else if (options[item].equals("Phone")) {
openFileChooser();
} else if (options[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
}
private void openFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, REQUEST_SELECT_FILE);
}
private void sendData() {
if (TextUtils.isEmpty(name.getText()) || TextUtils.isEmpty(mail.getText()) ||
TextUtils.isEmpty(telephone.getText()) || TextUtils.isEmpty(ausgang.getText())
|| TextUtils.isEmpty(ziels.getText()) || TextUtils.isEmpty(nachricht.getText())
|| TextUtils.isEmpty(file1.getText()) || TextUtils.isEmpty(file3.getText()) ||
TextUtils.isEmpty(file3.getText())) {
Toast.makeText(this, "Please fill out all fields.", Toast.LENGTH_SHORT).show();
} else {
if (agreement.isChecked()) {
if (isConnected()) {
ArrayList<String> data = new ArrayList<>();
data.add(name.getText().toString());
data.add(mail.getText().toString());
data.add(telephone.getText().toString());
data.add(ausgang.getText().toString());
data.add(ziels.getText().toString());
data.add(nachricht.getText().toString());
new SendMailTask(this).execute("metaphrase.online#gmail.com", "Admintogether-2000222",
"salman.footy.k7#gmail.com", "User Information", data.get(0), data.get(1),
data.get(2), data.get(3), data.get(4), data.get(5), getFullPath(attachments.get(0)),
getFullPath(attachments.get(1)), getFullPath(attachments.get(2)));
} else {
Toast.makeText(this, "Please check your internet connection and try again.", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "Please select the checkbox.", Toast.LENGTH_SHORT).show();
}
}
}
public boolean onOptionsItemSelected(#NonNull MenuItem item) {
if (eToggle.onOptionsItemSelected(item)) {
}
return true;
}
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.home:
startActivity(new Intent(Auftrag.this, MainActivity.class));
break;
case R.id.web:
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse("https://metaphrase.online"));
startActivity(browser);
break;
case R.id.help:
startActivity(new Intent(Auftrag.this, Feedback.class));
break;
case R.id.upload:
if (isConnected()) {
startActivity(new Intent(Auftrag.this, Auftrag.class));
} else {
Toast.makeText(this, "Bitte überprüfen Sie Ihre Internetverbindung!", Toast.LENGTH_SHORT)
.show();
}
break;
}
eDrawerlayout.closeDrawer(GravityCompat.START);
return true;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode != REQUEST_SELECT_FILE || resultCode != RESULT_OK) {
Toast.makeText(this, "No file selected.", Toast.LENGTH_SHORT).show();
dialog.setVisibility(View.GONE);
} else {
importFile(intent);
}
}
private void importFile(Intent intent) {
if (intent != null) {
String fileName = getFileName(intent.getData());
if (textfield != null) {
if (textfield.equals("btn1")) {
dialog.setVisibility(View.GONE);
file1.setText(fileName);
attachments.add(intent.getData());
} else if (textfield.equals("btn2")) {
dialog.setVisibility(View.GONE);
file2.setText(fileName);
attachments.add(intent.getData());
} else {
dialog.setVisibility(View.GONE);
file3.setText(fileName);
attachments.add(intent.getData());
}
} else {
Toast.makeText(this, "Try again later.", Toast.LENGTH_SHORT).show();
}
}
}
private String getFullPath(Uri fileUri) {
String filePath = null;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
try {
filePath = PathUtil.getPath(this, fileUri);
} catch (URISyntaxException e) {
e.printStackTrace();
}
} else {
File file = new File(fileUri.getPath());
final String[] split = file.getPath().split(":");
filePath = split[1];
}
return filePath;
}
private String getFileName(Uri data) {
Cursor cursor = getContentResolver().query(data, null, null, null, null);
if (cursor.getCount() <= 0) {
cursor.close();
throw new IllegalArgumentException("Can't obtain file name, cursor is empty");
}
cursor.moveToFirst();
String fileName = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
cursor.close();
return fileName;
}
public boolean isConnected() {
boolean connected = false;
try {
ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nInfo = cm.getActiveNetworkInfo();
connected = nInfo != null && nInfo.isAvailable() && nInfo.isConnected();
return connected;
} catch (Exception e) {
Log.e("Connectivity Exception", e.getMessage());
}
return connected;
}
}
So the problem should be in the <view ../> tag, the correct form is <View ... />. You should change your XML file with the following:
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f0f5f9"
tools:context="com.techsof.demoapp.Auftrag">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading_text"
android:textColor="#fff"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:id="#+id/form_heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/form_heading"
android:textColor="#4C4C4C"
android:textSize="20sp" />
<LinearLayout
android:id="#+id/form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form_heading"
android:layout_margin="10dp"
android:orientation="vertical">
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/name"
android:padding="10dp" />
<EditText
android:id="#+id/mail"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/mail_"
android:padding="10dp" />
<EditText
android:id="#+id/tel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Tel/Mobilnummer *"
android:padding="10dp" />
<EditText
android:id="#+id/aus"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Ausgangssprache *"
android:padding="10dp" />
<EditText
android:id="#+id/ziel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Zielsprache *"
android:padding="10dp" />
<EditText
android:id="#+id/nach"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:gravity="start"
android:hint="Nachricht *"
android:padding="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc1"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc2"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc3"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/footer_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form"
android:layout_margin="10dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/footer_text"
android:textColor="#4C4C4C"
android:textSize="12sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/footer_text"
android:layout_marginLeft="10dp"
android:buttonTint="#0F84AA"
android:fontFamily="serif"
android:text="#string/checkbox_text"
android:textColor="#4c4c4c"
android:textStyle="bold" />
<Button
android:id="#+id/sendBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/checkbox"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:text="#string/button_text"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/dialogBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4c4c4c"
android:padding="10dp"
android:text="#string/complete_action_using"
android:textColor="#fff"
android:textSize="20sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/cameraOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_camera_alt_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/camera"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/phoneStorageOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_folder_open_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/phone_storage"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:gravity="end"
android:padding="10dp">
<Button
android:id="#+id/cancelBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:backgroundTint="#0F84AA"
android:text="#string/cancel"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#f0f5f9"
app:headerLayout="#layout/nav_header"
app:itemIconTint="#000"
app:itemTextColor="#000"
app:menu="#menu/menu_main" />
</androidx.drawerlayout.widget.DrawerLayout>

Add Profile Picture to each account and stored into database - cloud Firestore

I want to make adding a Profile picture special it to the account and it's saved (store) into database - cloud Firestore as a special Profile picture for each account
for example to more explain:
there are two users use my application and all of them want special Profile picture for they Profile , how can I store this image to each of them in each database account and Display automatically if a user logs in to his Profile
following the code of the Profile java and activity
Profile.Java
public class Child_Profile extends AppCompatActivity {
private TextView name;
private TextView gender;
private TextView birth;
private TextView bload;
private TextView Text_Dates;
private TextView Text_Time;
private Button Button_record;
private TextView Text_record;
private TextView Text_hospial;
private TextView Text_Plan;
private TextView Text_Satus;
private TextView Text_Price;
private ImageView ImageView_choose_image;
private Button button_choose_image;
private Uri mUri;
private static final int GALLERY_INTENT = 1;
private StorageReference mStorage;
private DatabaseReference mData;
private FirebaseFirestore db = FirebaseFirestore.getInstance();
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu,menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.action_sign_out)
signOut();
return true;
}
private void signOut() {
AuthUI.getInstance().signOut(this)
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
startActivity(new Intent(Child_Profile.this,User.class));
finish();
}
});
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_child__profile);
name = findViewById(R.id.text_view_Namee);
gender = findViewById(R.id.text_view_Gender);
birth = findViewById(R.id.text_view_Birth);
bload = findViewById(R.id.text_view_Blood);
Text_Dates = findViewById(R.id.Text_Dates);
Text_Time = findViewById(R.id.Text_Time);
Text_record = findViewById(R.id.Text_record);
Text_hospial = findViewById(R.id.Text_hospial);
Text_Plan = findViewById(R.id.Text_Plan);
Text_Satus = findViewById(R.id.Text_Satus);
Button_record = findViewById(R.id.Button_record);
Text_Price = findViewById(R.id.Text_Price);
button_choose_image = findViewById(R.id.button_choose_image);
ImageView_choose_image = findViewById(R.id.ImageView_choose_image);
mStorage = FirebaseStorage.getInstance().getReference("Photo");
mData = FirebaseDatabase.getInstance().getReference("Photo");
button_choose_image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openFileChooser();
}
});
Intent in = getIntent();
final Bundle b = in.getExtras();
if (b != null) {
String n = (String) b.get("id");
db.collection("Child Profile").document(n).get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
#Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
String pName = documentSnapshot.getString("name");
String pgender = documentSnapshot.getString("gender");
String pbirth = documentSnapshot.getString("birth");
String pbload = documentSnapshot.getString("bload");
String pDates = documentSnapshot.getString("dates");
String pTime = documentSnapshot.getString("time");
String pHospital = documentSnapshot.getString("hospital");
String pPlan = documentSnapshot.getString("typeOfPlan");
String pSatus = documentSnapshot.getString("satus");
String pPrice = documentSnapshot.getString("price");
name.setText(pName);
gender.setText(pgender);
birth.setText(pbirth);
bload.setText(pbload);
Text_Dates.setText(pDates);
Text_Time.setText(pTime);
Text_hospial.setText(pHospital);
Text_Plan.setText(pPlan);
Text_Satus.setText(pSatus);
Text_Price.setText(pPrice);
}
});
}
}
private void openFileChooser() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, GALLERY_INTENT);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GALLERY_INTENT && resultCode == RESULT_OK && data != null && data.getData()!= null) {
mUri = data.getData();
Picasso.with(this).load(mUri).into(ImageView_choose_image);
}
}
public void ImageView_choose_image(View view) {
}
Profile.Xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#color/colorPrimaryDark"
android:orientation="vertical">
<ImageView
android:id="#+id/ImageView_choose_image"
android:layout_width="86dp"
android:layout_height="68dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="45dp"
android:onClick="ImageView_choose_image"/>
<Button
android:id="#+id/button_choose_image"
android:layout_width="wrap_content"
android:layout_height="68dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="-110dp"
android:background="#null"
android:text="chid Picture" />
<TextView
android:id="#+id/text_view_Namee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
android:text="Name"
android:textColor="#android:color/white"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
<android.support.v7.widget.CardView
android:layout_width="350dp"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="160dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/text_view_Gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/text_view_Birth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Birth Day"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/text_view_Blood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blood Type"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_marginTop="50dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:orientation="horizontal">
<ImageView
android:layout_width="50dp"
android:layout_height="65dp"
android:background="#drawable/calendar"/>
<TextView
android:id="#+id/Text_Dates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="Dates" />
<TextView
android:id="#+id/Text_Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="-35dp"
android:text="Time" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_marginTop="240dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginLeft="-1dp"
android:orientation="horizontal">
<LinearLayout
android:layout_marginTop="70dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:orientation="horizontal">
<ImageView
android:layout_width="50dp"
android:layout_height="65dp"
android:layout_marginTop="25dp"
android:background="#drawable/recodbook" />
<TextView
android:id="#+id/Text_Plan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Plan" />
<TextView
android:id="#+id/Text_Price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_marginLeft="-30dp"
android:padding="2dp"
android:text="Price" />
<TextView
android:id="#+id/Text_Satus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-30dp"
android:padding="2dp"
android:layout_marginTop="70dp"
android:text="Satus" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginLeft="180dp"
android:orientation="horizontal">
<LinearLayout
android:layout_marginTop="50dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:orientation="horizontal">
<Button
android:id="#+id/Button_record"
android:layout_width="50dp"
android:layout_height="65dp"
android:layout_marginLeft="20dp"
android:background="#drawable/record" />
<TextView
android:id="#+id/Text_record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="your record" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_marginTop="250dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginLeft="160dp"
android:orientation="horizontal">
<LinearLayout
android:layout_marginTop="70dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:orientation="horizontal">
<ImageView
android:layout_width="50dp"
android:layout_height="65dp"
android:layout_marginLeft="6dp"
android:layout_marginTop="5dp"
android:src="#drawable/medical" />
<TextView
android:id="#+id/Text_hospial"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:gravity="center"
android:text="your hospital" />
</LinearLayout>
</LinearLayout>

AsyncTask, LinearLayout Android Update visibility

I am trying to change visibility of a Linear Layout through findViewById() and then SetVisiblity(). But When I debug, I am seeing null values only.
Please find the snippet in the BackgroundMainActivity.java below in the onPostExecute() method.
I commented it. Please help.
MainActivity.java
button_getUsername.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
BackgroundMainActivity backgroundMainActivity = new BackgroundMainActivity(MainActivity.this, v);
backgroundMainActivity.execute("random", editText_username.getText().toString());
}
});
BackgroundMainActivity.java
public class BackgroundMainActivity extends AsyncTask<String, Void , String> {
public BackgroundMainActivity(Context ct, View view) {
context = ct;
rootView = view;
}
#Override
protected String doInBackground(String... params) {
String login_URL = "some url";
try {
String username = params[1];
URL url = new URL(login_URL);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoOutput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
String postData = URLEncoder.encode("username","UTF-8")+"="+URLEncoder.encode(username,"UTF-8");
bufferedWriter.write(postData);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
result = bufferedReader.readLine();
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPreExecute(){
}
#Override
protected void onPostExecute (String result){
if(result.equals("success")){
//need to make this change
//LinearLayout someLayout = (LinearLayout)rootview.findViewById(R.id.layout_content);
//someLayout.setVisibility(View.VISIBLE);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(result)
.setPositiveButton("Ok",null)
.show();
}
}
#Override
protected void onProgressUpdate(Void... values){
super.onProgressUpdate(values);
}
}
EDIT:
activity_main.xml
ss_layout_questions is gone by default. I want to make it visible once "result.equals( "success") " in BackgroundMainActivity.java.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.xtremustechnologies.chotu.useractivity.MainActivity">
<android.support.v4.widget.NestedScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#color/lightGreen"
android:layout_gravity="top">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/textviewr2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:text="CHOTU"
android:textColor="#color/white"
android:textSize="40dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="40dp"
android:text="Your Personal Assistant"
android:textColor="#color/white"
android:textSize="12dp" />
</LinearLayout>
<TextView
android:id="#+id/ss_textview_questions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="40dp"
android:text="Security Questions "
android:textColor="#color/black"
android:textSize="20dp"
android:visibility="gone"/>
<EditText
android:id="#+id/ss_et_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:hint="Enter Username" />
<Button
android:id="#+id/ss_button_getusername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/ss_et_username"
android:layout_centerHorizontal="true"
android:onClick="clickGetUsername"
android:layout_gravity="center_horizontal"
android:text="Submit" />
<LinearLayout
android:id="#+id/ss_layout_questions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textviewr3"
android:layout_centerHorizontal="false"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:orientation="horizontal">
<Button
android:id="#+id/ss_button_dob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginRight="50dp"
android:text="Date of Birth" />
<TextView
android:id="#+id/ss_textView_dob"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical|center_horizontal"
android:layout_weight="1"
android:text="TextView"
android:textSize="20dp" />
</LinearLayout>
<TextView
android:id="#+id/ss_textView_question1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_marginTop="30dp" />
<EditText
android:id="#+id/ss_textView_ans1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:hint="Enter your answer here" />
<TextView
android:id="#+id/ss_textView_question2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_marginTop="30dp" />
<EditText
android:id="#+id/ss_textView_ans2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:hint="Enter your answer here" />
<TextView
android:id="#+id/ss_textView_question3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_marginTop="30dp" />
<EditText
android:id="#+id/ss_textView_ans3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:hint="Enter your answer here" />
<Button
android:id="#+id/ss_button_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#color/black"
android:text="Submit"
android:textColor="#color/white" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.constraint.ConstraintLayout>
Its working finally. Here is what I did
I added a new class inside BackgroundMainActivity.java and then called it in the onPostExecute() method.
class a{
public Button button_reset, button_dob;
public LinearLayout layout_questions;
public TextView textView_title;
public EditText editText_username;
public void makeVisible(ForgotPasswordActivity context){
LinearLayout layout_questions = (LinearLayout) context.findViewById(R.id.ss_layout_questions);
layout_questions.setVisibility(View.VISIBLE);
}
onPostExecute() in BackgroundMainActivity.java
a obj = new a();
obj.makeVisible((ForgotPasswordActivity) context);
Yes, you should get NPE error. Why? Because look at this code:
button_getUsername.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
BackgroundMainActivity backgroundMainActivity = new BackgroundMainActivity(MainActivity.this, v);
backgroundMainActivity.execute("random", editText_username.getText().toString());
}
});
Here, you are trying to pass a Button (your button_getUserName) to your AsyncTask. Then when you find the view, of course, there's no layout in your button.
How to resolve it? Actually, it's very easy, just pass your layout in the constructor of the AsyncTask as:
BackgroundMainActivity backgroundMainActivity = new BackgroundMainActivity(MainActivity.this, findViewById(R.id.layout_content));
// do on onPost:v.setVisibility...

How Can I put an Image on another Image that i am taking from you tube?

Problem is that I am taking thumbnail from Youtube of the video and when I am clicking on that Image that is redirecting me to Youtube but problem is that i want to show the image of a play Icon on that Image that I am taking from Youtube..Hope so u have Understood what I am asking.
can any One Help me.
package com.dotocto.ipartner;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.dotocto.ipartner.dataset.VedioDataSet;
import com.dotocto.ipartner.netio.WebServices;
import com.dotocto.ipartner.patten.ImageLoader;
import com.dotocto.ipartner.patten.UtilClassForValidations;
public class VideoScreen extends Activity implements OnClickListener {
private ImageView[] images;
private ImageLoader imageloader;
//private ImageView imageView;
private TextView vedio_text;
private LinearLayout image_layout;
ArrayList<VedioDataSet> imageslist;
ImageView i11;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.video_screen);
try{
vedio_text = (TextView)findViewById(R.id.vedio_text);
image_layout = (LinearLayout)findViewById(R.id.image_layout);
imageloader = new ImageLoader(VideoScreen.this);
imageslist = new ArrayList<VedioDataSet>();
i11= (ImageView) findViewById(R.id.imageView1);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
try{
LinearLayout vedio_lay = (LinearLayout) findViewById(R.id.vedio_lay);
vedio_lay.setBackgroundResource(R.drawable.selected);
vedio_text .setTextColor(android.graphics.Color.BLUE);
if(imageslist == null || imageslist.size() <= 0)
{
new PostDataToServer().execute();
}
}catch (Exception e) {
// TODO: handle exception
}
}
class PostDataToServer extends AsyncTask<String, Integer, ArrayList<VedioDataSet>> {
#Override
protected ArrayList<VedioDataSet> doInBackground(String... arg0)
{
return WebServices.VedioActivity();
}
#Override
protected void onPostExecute(ArrayList<VedioDataSet > result)//onPostExecute(Result), invoked on the UI thread after the background computation finishes. The result of the background computation is passed to this step as a parameter.
{
// TODO Auto-generated method stub
super.onPostExecute(result);
// if(pd != null && pd.isShowing())
// pd.dismiss();
try{
if(result != null)
{
if(result.get(0).getStatus().equalsIgnoreCase("success"))
{
imageslist = result;
for(int j=0; j<imageslist.size(); j++)
{
LinearLayout hlinearlayout = new LinearLayout(VideoScreen.this);
hlinearlayout.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
1f);
hlinearlayout.setWeightSum(3);
final VedioDataSet record1 = imageslist.get(j);
ImageView img1 = new ImageView(VideoScreen.this);
LinearLayout.LayoutParams params1 = layoutParams;
params1.weight = 1f;
params1.setMargins(2, 2, 2, 2);
img1.setLayoutParams(params1);
img1.setVisibility(View.VISIBLE);
img1.setTag(record1.getYoutubeimg());
//i11.setVisibility(View.VISIBLE);
imageloader.DisplayImage(record1.getYoutubeimg(), VideoScreen.this, img1);
hlinearlayout.addView(img1);
playVideo(img1,record1);
j ++;
if(j < imageslist.size())
{
final VedioDataSet record2 = imageslist.get(j);
ImageView img2 = new ImageView(VideoScreen.this);
LinearLayout.LayoutParams params2 = layoutParams;
params2.weight = 1f;
params2.setMargins(2, 2, 2, 2);
img2.setLayoutParams(params2);
img2.setVisibility(View.VISIBLE);
img2.setTag(record2.getYoutubeimg());
imageloader.DisplayImage(record2.getYoutubeimg(), VideoScreen.this, img2);
hlinearlayout.addView(img2);
playVideo(img2,record2);
}
j++;
if(j < imageslist.size())
{
final VedioDataSet record3 = imageslist.get(j);
ImageView img3 = new ImageView(VideoScreen.this);
LinearLayout.LayoutParams params3 = layoutParams;
params3.weight = 1f;
params3.setMargins(2, 2, 2, 2);
img3.setLayoutParams(params3);
img3.setVisibility(View.VISIBLE);
img3.setTag(record3.getYoutubeimg());
imageloader.DisplayImage(record3.getYoutubeimg(), VideoScreen.this, img3);
hlinearlayout.addView(img3);
playVideo(img3,record3);
}
image_layout.addView(hlinearlayout);
}
}
else
UtilClassForValidations.alatMassageBox(VideoScreen.this,result.get(0).getErrormsg() );
}
else
UtilClassForValidations.alatMassageBox(VideoScreen.this, "We're sorry! There has been some error " +
"occured during serching video screen images and vedios. Please try again after some time.");
}
catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
}
}
public void playVideo(ImageView x ,final VedioDataSet y){
x.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
try
{
if(y.getVideourl() != null && y.getVideourl().length() >0)
{
Uri uri = Uri.parse(y.getVideourl());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
// finish();
}
else
{
UtilClassForValidations.alatMassageBox(VideoScreen.this, "We're sorry! " +
" The video Url is can not provided by server side" +
" Please try again after some time.");
}
}
catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
}
});
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId())
{
case R.id.give_icon:
Intent give = new Intent(VideoScreen.this, PaymentActivity.class);
give.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(give);
// finish();
break;
case R.id.blog_icon:
Intent blog = new Intent(VideoScreen.this, BlogActivity.class);
blog.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(blog);
// finish();
break;
case R.id.arms_icon:
Intent vedio = new Intent(VideoScreen.this, PartnershipArms.class);
vedio.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(vedio);
// finish();
break;
case R.id.icon_contact:
Intent contact = new Intent(VideoScreen.this, ContactUsActivity.class);
contact.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(contact);
// finish(;
break;
}
}
}
// this is my XML
<?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:background="#drawable/inner_bg"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/header_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/bottom_bg" >
<TextView
android:id="#+id/header_bar_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="VIDEOS"
android:textColor="#ffffff"
android:textSize="20sp"
android:typeface="normal" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout"
android:layout_below="#+id/header_bar"
android:layout_centerHorizontal="true"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/image_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/image_ineerlayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="3" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/bottom_bg"
/>"
<ImageView
android:id="#+id/imageView1"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1"
android:keepScreenOn="true"
android:clickable="true"/>
</FrameLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1"
android:keepScreenOn="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/image_ineerlayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/image_ineerlayout4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm9"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm10"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView88"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1"
android:keepScreenOn="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm11"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView77"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1"
android:keepScreenOn="true"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/bottom_bg"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/bott_iner_linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginTop="12dp"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<com.dotocto.ipartner.patten.SAutoBgButton
android:id="#+id/arms_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:background="#drawable/arms_icon"
android:onClick="onClick" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="ARMS"
android:textColor="#ffffff"
android:textSize="14sp"
android:typeface="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:orientation="vertical" >
<com.dotocto.ipartner.patten.SAutoBgButton
android:id="#+id/give_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:background="#drawable/give_icon"
android:onClick="onClick" />
<TextView
android:id="#+id/give_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GIVE"
android:textColor="#ffffff"
android:textSize="14sp"
android:typeface="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:orientation="vertical" >
<com.dotocto.ipartner.patten.SAutoBgButton
android:id="#+id/blog_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:background="#drawable/blog_icon"
android:onClick="onClick" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="BLOG"
android:textColor="#ffffff"
android:textSize="14sp"
android:typeface="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:orientation="vertical" >
<com.dotocto.ipartner.patten.SAutoBgButton
android:id="#+id/vedio_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginTop="2dp"
android:background="#drawable/vedio_icon"
android:onClick="onClick" />
<TextView
android:id="#+id/vedio_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="VIDEO"
android:textColor="#ffffff"
android:textSize="14sp"
android:typeface="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<com.dotocto.ipartner.patten.SAutoBgButton
android:id="#+id/icon_contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:background="#drawable/icon_contact"
android:onClick="onClick" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:text="CONTACT US"
android:textColor="#ffffff"
android:textSize="14sp"
android:typeface="normal" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
to use overlapping images in layout you can use frame layout http://developer.android.com/reference/android/widget/FrameLayout.html

how to store text value for a radiogroup in sqlite database?

i've a radio group radiogoup1 that hat two radiobutton rbtn1, rbtn2. say i want to store Male for rbtn1 and Female for rbtn2 in database. How to do it? I am mentioning the .xml and .java file.
sqlliteexample.xml :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="#string/age" >
</TextView>
<EditText
android:id="#+id/editAge"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textContcat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="#string/contact" />
<EditText
android:id="#+id/editContact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textMultiLine" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/sLabel"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left|center"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:text="#string/sx" />
<RadioGroup
android:id="#+id/RadioGroup01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/malebutton"
android:layout_width="wrap_content"
android:layout_height="17dp"
android:text="#string/mal"
android:textSize="15sp" />
<RadioButton
android:id="#+id/femalebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/femal"
android:textSize="15sp" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/savebutton"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:gravity="left|center"
android:text="#string/save"
android:textSize="13sp" />
<Button
android:id="#+id/viewbutton"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_gravity="center"
android:gravity="center|left"
android:text="#string/view"
android:textSize="13sp" />
</LinearLayout>
SqlLiteExample.java :
public class SqlLiteExample extends Activity implements OnClickListener, OnCheckedChangeListener {
Button sqlUpdate, sqlView;
EditText etName,etAge,etContact;
RadioGroup rdgrp;
RadioButton selectedRadioButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sqlliteexample);
sqlUpdate = (Button) findViewById(R.id.savebutton);
etName = (EditText) findViewById(R.id.editName);
etAge = (EditText) findViewById(R.id.editAge);
etContact = (EditText) findViewById(R.id.editContact);
rdgrp.setOnCheckedChangeListener(this);
sqlView = (Button) findViewById(R.id.viewbutton);
sqlView.setOnClickListener(this);
sqlUpdate.setOnClickListener(this);
}
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.savebutton:
boolean didWork = true;
try{
String name = etName.getText().toString();
String age = etAge.getText().toString();
String contact = etContact.getText().toString();
MyDB entry = new MyDB(SqlLiteExample.this);
entry.open();
entry.createEntry(name,age,contact);
entry.close();
}catch(Exception e){
didWork = false;
String error = e.toString();
Dialog d = new Dialog(this);
d.setTitle("Error");
TextView tv = new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();
}finally{
if(didWork){
Dialog d = new Dialog(this);
d.setTitle("Updated");
TextView tv = new TextView(this);
tv.setText("Success");
d.setContentView(tv);
d.show();
}
}
break;
case R.id.viewbutton:
Intent i = new Intent("com.bysakiralam.mydatabase.DISPLAYRECORDS");
startActivity(i);
break;
}
}
#Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
switch(arg1){
case R.id.malebutton:
break;
case R.id.femalebutton:
break;
}
} }
There is no need to override onCheckedChanged() use following in your on savebutton click
rdgrp=(RadioGroup)findViewById(R.id.RadioGroup01);
String radiovalue= (RadioButton)this.findViewById(rdgrp.getCheckedRadioButtonId())).getText().toString();
and now use radiovalue to store in database
Edit: forget (
rdgrp=(RadioGroup)findViewById(R.id.RadioGroup01);
String radiovalue= ((RadioButton)this.findViewById(rdgrp.getCheckedRadioButtonId())).getText().toString();
try this
myRadioGrp=(RadioGroup)findViewById(R.id.RadioGroup01);
String radiovalue= ((RadioButton)this.findViewById(myRadioGrp.getCheckedRadioButtonId())).getText().toString();

Categories

Resources