我需要这个应用程序的一些帮助。我不知道删除或更改了什么,以便在没有类别的情况下显示引号中的文字。我的意思是当我按下按钮时,show apper随机而不选择类别。我想删除那些类别。 我花了2个小时,但我是初学者,我没有找到好办法。
package com.sv.lovr;
import java.util.ArrayList;
import java.util.Random;
import com.conceptapps.lovr.R;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
ArrayList<Quotes> quotes = new ArrayList<Quotes>();
Quotes qs = null;
Context context;
private AdView adView;
Your ad unit id. Replace with your actual ad unit id. */
private static final String AD_UNIT_ID = "ca-app-pub-3126879690773207/7823002769";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
context = this;
LinearLayout layout = (LinearLayout) findViewById(R.id.ads_lin);
layout.addView(adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("5B895A3CC0CA50D56506E300A4C8342B")
.addTestDevice("D039292A1F434C999B21503D63D6FD88")
.addTestDevice("TEST_EMULATOR").build();
Start loading the ad in the background.
adView.loadAd(adRequest);
ImageView share = (ImageView) findViewById(R.id.sharebtn);
ImageView about = (ImageView) findViewById(R.id.about);
Button btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
loadCategory();
Quotes q = randomString();
qs = q;
TextView text_quote = (TextView) findViewById(R.id.quote);
//TextView text_categ = (TextView) findViewById(R.id.category);
if (q != null) {
text_quote.setText(q.getQuote());
text_categ.setText(q.getCateg());
}
}
});
share.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (qs != null) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, qs.getQuote());
sendIntent.setType("text/plain");
startActivity(sendIntent);
} else {
Toast.makeText(getApplicationContext(),
"Press the lovely button first", Toast.LENGTH_LONG)
.show();
}
}
});
}
about.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
TextView text = new TextView(getApplicationContext());
text.setText("\nLovr is a mobile application designed for all men who want to surprise their life partners. Because we know that the man is not the most creative being on Earth... for God, man is a fighter,a true warrior,he has no time for creative ideas,romantic stuff.But with this app, men from all over the world can surprise their life partners with unique ideas for dating, romantic, dirty or funny messages, and many other things that will make partner loves you more and more.\n\nAttention! For it's best results, confidence, body language, sense of humor skills are highly requiered. More details can be found in the links below.\n David DeAngelo\nhttp://www.doubleyourdating.com/\nThe Attraction Forums \n http://www.theattractionforums.com/ \n Simple Pickup \n https://www.simplepickup.com/ \n Succes Dublu \n http://succesdublu.ro/ \n Double Your Dating | Learn About My eBook \n www.doubleyourdating.com \n\nApp created by:\n Stroe Andrei Catalin\nE-mail:catalin2402@yahoo.com\n\n Visan Tiberiu\n E-mail:tiberiu.visan@yahoo.ro");
ScrollView scroll = new ScrollView(getApplicationContext());
LinearLayout layout = new LinearLayout(getApplicationContext());
layout.addView(text);
scroll.addView(layout);
alertDialogBuilder.setView(scroll);
// set dialog message
alertDialogBuilder.setCancelable(false)
.setPositiveButton("Ok", null).setTitle("About");
// create alert dialog
final AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog
.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button b = alertDialog
.getButton(AlertDialog.BUTTON_POSITIVE);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
}
});
// show it
alertDialog.show();
}
});
}
@Override
public void onResume() {
super.onResume();
if (adView != null) {
adView.resume();
}
}
@Override
public void onPause() {
if (adView != null) {
adView.pause();
}
super.onPause();
}
/** Called before the activity is destroyed. */
@Override
public void onDestroy() {
// Destroy the AdView.
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
/*public void loadCategory() {
CheckBox check0 = (CheckBox) findViewById(R.id.radio0);
CheckBox check1 = (CheckBox) findViewById(R.id.radio1);
CheckBox check2 = (CheckBox) findViewById(R.id.radio2);
CheckBox check3 = (CheckBox) findViewById(R.id.radio3);
String[] categ;
quotes.clear();
if (check0.isChecked()) {
categ = getResources().getStringArray(R.array.categ1);
for (int i = 0; i < categ.length; i++) {
Quotes c = new Quotes(categ[i], getResources().getString(
R.string.categ_1));
quotes.add(c);
}
}
if (check1.isChecked()) {
categ = getResources().getStringArray(R.array.categ2);
for (int i = 0; i < categ.length; i++) {
Quotes c = new Quotes(categ[i], getResources().getString(
R.string.categ_2));
quotes.add(c);
}
}
if (check2.isChecked()) {
categ = getResources().getStringArray(R.array.categ3);
for (int i = 0; i < categ.length; i++) {
Quotes c = new Quotes(categ[i], getResources().getString(
R.string.categ_3));
quotes.add(c);
}
}
if (check3.isChecked()) {
categ = getResources().getStringArray(R.array.categ4);
for (int i = 0; i < categ.length; i++) {
Quotes c = new Quotes(categ[i], getResources().getString(
R.string.categ_4));
quotes.add(c);
}
}
}
public Quotes randomString() {
int size = quotes.size();
Quotes selected_quote = null;
Random r = new Random();
if (size != 0) {
int number = r.nextInt(size);
selected_quote = quotes.get(number);
} else {
Toast.makeText(getApplicationContext(), "Please select a category",
Toast.LENGTH_LONG).show();
}
return selected_quote;
}
}
答案 0 :(得分:0)
我真的不明白你的问题,但是,从我的理解来看。要使代码至少编译,您需要:
1)评论此行:
Start loading the ad in the background.
所以看起来应该是这样的:
//Start loading the ad in the background.
2)评论或删除代码中的所有loadCategory();
希望有所帮助
答案 1 :(得分:-1)
我评论了一行loadCateogy();但没有运气。如果未选中类别,则在按下按钮时不会显示文本。