在我的应用程序中,我有两个复选框,一个是 PayByCredit ,还有一个是 PaybySMS 两个复选框都不可见问题是什么?为了显示复选框,我给出了像android:visibility="visible"
这样的代码,但仍然没有用。请问有人可以帮我解决这个问题吗?
我的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="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>
我的.java代码在这里:
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));
}
}
}
请帮我解决这个问题??
答案 0 :(得分:0)
在你的代码中试试这个:
paybycard.setVisibility(0);
paybysms.setVisibility(0);
希望得到这个帮助,谢谢
答案 1 :(得分:0)
删除android:background="@null"
答案 2 :(得分:0)
这些布局对我有用:
<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" />