Android Theme.AppCompat theme [duplicate] - java

This question already has answers here:
Cannot create AlertDialog: AppCompat error
(2 answers)
Closed 6 years ago.
My app crashes when I invoke alert dialogue within a list item. My app lists cars, every item has 2 buttons, each button calls alertdialog for yes/no answer. the app crashes with "You need to use a Theme.AppCompat theme (or descendant) with this activity." everytime I press the button. App code is as follows:
AndroidManifest:
<activity android:name=".SplashScreen" android:theme="#style/generalnotitle">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".CarActivity" android:theme="#style/generalnotitle"></activity>
</application>
Style:
<resources>
<style name="generalnotitle" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:screenOrientation">portrait</item>
</style>
</resources>
CarActivity.java
public class CarActivity extends AppCompatActivity {
String[] car_tag, car_makemodel, car_owner_id;
TypedArray car_pic;
String[] aa_owner_id, aa_owner_name, aa_owner_tlf;
String tlf, name;
List<CarItem> carItems;
ListView mylistview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e("list start", "list start" );
getSupportActionBar().hide();
setContentView(R.layout.activity_list);
mylistview = (ListView) findViewById(R.id.LList);
setUpListView();
}
public void setUpListView() {
carItems = new ArrayList<CarItem>();
// gets car info
car_pic = getResources().obtainTypedArray(R.array.a_carpic);
car_tag = getResources().getStringArray(R.array.a_mat);
car_makemodel = getResources().getStringArray(R.array.a_makemodel);
car_owner_id = getResources().getStringArray(R.array.a_owner);
//defines items
for (int i = 0; i < car_tag.length; i++){
CarItem item = new CarItem(car_pic.getResourceId(i, -1), car_tag[i], car_makemodel[i], car_owner_id[i]);
Log.e("CarActivity", car_tag[i] );
carItems.add(item);
}
//gets available owners
aa_owner_id = getResources().getStringArray(R.array.a_id);
aa_owner_name = getResources().getStringArray(R.array.a_name);
aa_owner_tlf = getResources().getStringArray(R.array.a_tlf);
//populates the list
CarAdapter adapter = new CarAdapter(getApplicationContext(), carItems, aa_owner_id , aa_owner_name, aa_owner_tlf);
mylistview.setAdapter(adapter);
}
}
CarAdapter.java
public class CarAdapter extends BaseAdapter {
Context context;
List<CarItem> carItems;
String [] a_owner_id, a_owner_names, a_owner_tlf;
String name, tlf, owner_id;
CarAdapter(Context context, List<CarItem> carItems, String [] a_owner_id, String [] a_owner_names, String [] a_owner_tlf){
this.context = context;
this.carItems = carItems;
this.a_owner_id = a_owner_id;
this.a_owner_names = a_owner_names;
}
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null){
convertView = mInflater.inflate(R.layout.row_car,null);
holder = new ViewHolder();
holder.car_pic = (ImageView) convertView.findViewById(R.id.car_pic);
holder.tag = (TextView) convertView.findViewById(R.id.tag);
holder.makemodel = (TextView) convertView.findViewById(R.id.make_model);
holder.owner = (TextView) convertView.findViewById(R.id.owner);
holder.blck = (Button) convertView.findViewById(R.id.block);
holder.mov = (Button) convertView.findViewById(R.id.move);
CarItem row_pos = carItems.get(position);
holder.car_pic.setImageResource(row_pos.getCar_pic());
holder.tag.setText(row_pos.getTag());
holder.makemodel.setText(row_pos.getMakemodel());
owner_id = row_pos.getOwner();
getOwner(owner_id);
holder.owner.setText(name);
holder.blck.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBlockClick();
}
});
holder.mov.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.e("CarAdapter move click", owner_id );
}
});
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
private void onBlockClick() {
Log.e("CarActivity", "CLICK block button" );
AlertDialog.Builder alertDlg = new AlertDialog.Builder(context);
alertDlg.setMessage("Do you wish to inform " + name + "?");
alertDlg.setCancelable(false);
alertDlg.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//Get owner phone number
getNumber(owner_id);
Log.e("CarActivity YES DIALOG", tlf );
//Toast.makeText(getApplicationContext(),"Afasta-me o teu cangalho...", Toast.LENGTH_SHORT).show();
}
});
alertDlg.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Log.e("CarActivity", "CLICK NO DIALOG" );
}
});
alertDlg.create().show();
}
}
SOLUTION: when I set adapter, i was sending "getApplicationContext()" but instead i sent "this" and this way i could send the context to the adapter.
CarActivity.java:
before:
CarAdapter adapter = new CarAdapter(getApplicationContext(), carItems, aa_owner_id , aa_owner_name, aa_owner_tlf);
after:
CarAdapter adapter = new CarAdapter(this, carItems, aa_owner_id , aa_owner_name, aa_owner_tlf);

Have you tried using the constructor that takes the dialog's theme as well?
Try this:
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.generalnotitle);
Then put the rest of the relevant code for the builder.
Note, the theme should point to a dialog theme (Theme.AppCompat.Light.Dialog.Alert). Check out this post for more details.
http://www.materialdoc.com/alerts/

There are two AlertDialog classes: the regular android.app.AlertDialog, and the support/appcompat version android.support.v7.app.AlertDialog. I can't tell which one you are importing, but the latter one requires you to be using an appcompat theme for the given Context, which should not be a problem if you are already using the AppCompat library and your activities extend from AppCompatActivity. (If you aren't using AppCompat, then you should make sure you are using the regular AlertDialog.)

Related

Building a Andoid browser

I am new to android studio.. I am building android web browser for my pleasure. Here, I'm confused about the adding new tabs. I used fragment for tabs. I created a button on mainactivity layout and when clicked the button it gonna add new fragment to fragment container..
something like this,
public void add_tab()
{
id++;
int next_id = id+1;
String tag = String.valueOf(id);
Bundle bundle = new Bundle ();
bundle.putString ("tag",tag);
bundle.putInt ("id",id);
bundle.putInt ("next_id",next_id);
final FrameLayout tab_hosting_frame = new FrameLayout(getApplicationContext ());
FrameLayout.LayoutParams layoutparams_match_parent_match_parent = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT,Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);
tab_hosting_frame.setLayoutParams(layoutparams_match_parent_match_parent);
tab_hosting_frame.setBackgroundColor (Color.BLUE);
tab_hosting_frame.setId (id);
FragmentManager fragment_manager1 = getSupportFragmentManager ();
New_Tab new_tab_fragment = new New_Tab ();
FragmentTransaction fr_transaction = fragment_manager1.beginTransaction ();
fr_transaction.add ((tab_hosting_frame.getId ()),new_tab_fragment,tag);
fr_transaction.addToBackStack ("Fragment Add");
//new_tab_fragment.setArguments (bundle);
new_tab_fragment.setArguments (bundle);
fr_transaction.commit ();
tab_hosting_layout.addView (tab_hosting_frame);
//tab_hosting_layout.setVisibility (View.VISIBLE);
}
I tried this way also
public View create_tab()
{
id++;
String tag = String.valueOf(id);
linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View tab_view = new View (getApplicationContext ());
tab_view = linflater.inflate(R.layout.new_tab_view, null);
TextView show_id = (TextView)tab_view.findViewById (R.id.tab_id);
show_id.setText (tag);
tab_hosting_layout.addView (tab_view);
return tab_view;
}
then execute then when button clicked,
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
tab_hosting_layout = (ConstraintLayout)findViewById (R.id.tab_host);
add_tab_button = (Button) findViewById (R.id.add_tab_button);
add_tab_button.setOnClickListener (
new View.OnClickListener ()
{
#Override
public void onClick(View v)
{
add_tab ();
//or
//create_tab ();
}
}
);
In 2nd methode, thing is, when I click the back button once ,all added tabs(views) are gone once. not step by step one by one..
Is this methode ok?? or is there another methode or way to create unlimited tabs like in normal web browser? I am bit confused weather iam wrong or not..
If u guys know help me with any solution...

How to change the background color of every item in a ListView?

I am developing an app which has a text message interface (something like Facebook Messenger, Whatsapp, etc). I want to be able to change the background color of all the chat bubbles (a ListView of TextViews) sent by the user when they pick a new color (in a NavigationView).
However, with the current code that I have, I only am able to change the color after the EditText used to compose the message is clicked again. Or I am able to only edit the first bubble sent, but as soon as the color is changed.
Here's what I tried :
ItemColor1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
Toast.makeText(activity, "Couleur mise à jour", Toast.LENGTH_SHORT).show();
currentTheme = position;
SharedPreferences.Editor editor = pref.edit();
editor.putInt("indexColorSelected",currentTheme);
editor.apply();
chatAdapter.notifyDataSetChanged();
//the following changes only the first message sent
for(int i=0; i<chatAdapter.getCount(); i++){
ChatData message = chatMessageList.get(position);
TextView msg = activity.findViewById(R.id.text);
msg.setText(message.body);
msg.setBackgroundResource(R.drawable.user_color1);
}
}
});
ChatData is a custom Class that I created which looks like this :
public class ChatAdapter extends BaseAdapter {
private static LayoutInflater inflater = null;
private ArrayList<ChatData> chatMessageList;
private Context mContext;
ChatAdapter(Activity activity, ArrayList<ChatData> list) {
mContext = activity;
chatMessageList = list;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
...
}
Color drawable:
<corners
android:bottomRightRadius="5dp"
android:radius="40dp"/>
<gradient
android:angle="45"
android:endColor="#01f1fa"
android:startColor="#0189ff"
android:type="linear" />
</shape>
getView() method of the Adapter:
public View getView(int position, View convertView, ViewGroup parent) {
ChatData message = chatMessageList.get(position);
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.msglist, parent, false);
TextView msg = vi.findViewById(R.id.text);
msg.setText(message.body);
LinearLayout layout = vi.findViewById(R.id.message_layout);
LinearLayout parent_layout = vi.findViewById(R.id.message_layout_parent);
inflater = (LayoutInflater) this.mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// if message is mine then align to right
if (message.isMine) {
layout.setGravity(Gravity.RIGHT);
int couleurBubble = getCouleurSelectionnee();
switch(couleurBubble){
case R.color.c1: msg.setBackgroundResource(R.drawable.user_color1); break;
case R.color.c2: msg.setBackgroundResource(R.drawable.user_color2); break;
case R.color.c3: msg.setBackgroundResource(R.drawable.user_color3); break;
case R.color.c4: msg.setBackgroundResource(R.drawable.user_color4); break;
case R.color.c5: msg.setBackgroundResource(R.drawable.user_color5); break;
case R.color.c6: msg.setBackgroundResource(R.drawable.user_color6); break;
case R.color.c7: msg.setBackgroundResource(R.drawable.user_color7); break;
case R.color.c8: msg.setBackgroundResource(R.drawable.user_color8); break;
default: break;
}
parent_layout.setGravity(Gravity.RIGHT);
}
// If not mine then align to left
else {
layout.setGravity(Gravity.LEFT);
msg.setBackgroundResource(R.drawable.bot_chat);
parent_layout.setGravity(Gravity.LEFT);
}
return vi;
}
I don't really know where to go from here so any kind of help would be appreciated. If you want me to provide more code, let me know and I will.
Thank you.
I'm sharing how I would do it. Maybe, this can help you.
There's some strange issue because you are calling notifyDataSetChanged(). This would be enough to re-draw all message bubbles.
My ideia is:
Add a int variable to the adapter class (mColorResource). This variable will point to the proper drawable that should be used (like R.drawable.user_color1).
public class ChatAdapter extends BaseAdapter {
int mColorResource;
ChatAdapter(Activity activity, ArrayList<ChatData> list, int initialColorResource) {
mContext = activity;
chatMessageList = list;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// You must receive the color on the construtor
mColorResource = initialColor;
}
// Use this method to update the color (when user select a new color)
public void setColor(int newColorResource) {
mColorResource = newColorResource;
}
public View getView(int position, View convertView, ViewGroup parent) {
...
// Note how this if-else is cleaner now
if (message.isMine) {
layout.setGravity(Gravity.RIGHT);
msg.setBackgroundResource(mColorResource);
parent_layout.setGravity(Gravity.RIGHT);
} else {
layout.setGravity(Gravity.LEFT);
msg.setBackgroundResource(R.drawable.bot_chat);
parent_layout.setGravity(Gravity.LEFT);
}
...
}
}
Then, when a color is selected, find the proper drawable based on the view clicked and pass it to the adapter:
ItemColor1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
Toast.makeText(activity, "Couleur mise à jour", Toast.LENGTH_SHORT).show();
currentTheme = position;
SharedPreferences.Editor editor = pref.edit();
editor.putInt("indexColorSelected", currentTheme);
editor.apply();
// Here, you send the proper drawable...
// I'm not sure how you convert color selected to the drawable
// So, add your logic to convert the button clicked to a drawable here
// like R.drawable.user_color1
chatAdapter.setColor(R.drawable.NAME_OF_THE_COLOR);
// Request to re-draw all items from the list (all bubbles)
chatAdapter.notifyDataSetChanged();
}
});
Also, on your activity, you create the adapter with the last used color. Something like:
#Override
protected void onCreate(#Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
....
// Set a default color (if user is open you app for the first time)
int chatColor = R.drawable.user_color1;
// Add your logic to read the shared preference and convert that last color used to a valid drawable.
// Like chatColor = pref.getInt(indexColorSelected, R.drawable.user_color1) etc....
// Set the color in the adapter.
chatAdapter = newAdapter(this, mChatDataList, chatColor);
}

Add item to a specific column in ListView Adapter

I have an increment system and I want when onClick to save value from DialogAlert in a column in ListView Adapter.
Here is my Adapter:
public class VanzatorProduseList extends ArrayAdapter<VanzatorProduse> {
private Activity context;
private SparseBooleanArray selectedListItemsIds;
private List<VanzatorProduse> vanzatorProduseList;
public VanzatorProduseList(Activity context, List<VanzatorProduse> vanzatorProduseList){
super(context, R.layout.list_produse_vanzator, vanzatorProduseList);
this.context = context;
selectedListItemsIds = new SparseBooleanArray();
this.vanzatorProduseList = vanzatorProduseList;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listViewItem = inflater.inflate(R.layout.list_produse_vanzator, null, true);
TextView textViewProdus1 = (TextView) listViewItem.findViewById(R.id.textViewProdus1);
TextView textViewPret1 = (TextView) listViewItem.findViewById(R.id.textViewPret1);
final TextView textViewCantitate1 = (TextView) listViewItem.findViewById(R.id.textViewCantitate1);
final VanzatorProduse vanzatorProduse = vanzatorProduseList.get(position);
textViewProdus1.setText(vanzatorProduse.getProdus());
textViewPret1.setText(vanzatorProduse.getPret());
textViewCantitate1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog_alert);
dialog.setTitle("Alege Canitatea");
// set the custom dialog components - text, image and button
final Button dialogBtn = (Button) dialog.findViewById(R.id.dialog_btn);
final ElegantNumberButton elegantNumberButton = (ElegantNumberButton) dialog.findViewById(R.id.elegantNumberButton);
// if button is clicked, close the custom dialog
dialogBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String num = elegantNumberButton.getNumber();
vanzatorProduseList.add(num);
dialog.dismiss();
}
});
dialog.show();
}
});
return listViewItem;
}
Here is what I tried but I got an error and no idea what to do next :
String num = elegantNumberButton.getNumber();
vanzatorProduseList.add(num);
Error:
'add(com.dev.darius.neglije.Vanzator.ListaProduse.VanzatorProduse)' in 'java.util.List' cannot be applied to '(java.lang.String)'
Here I'm stuck I want to display in TextView called textViewCantitate1.
Hope you understand.
As stated in earlier answers by #jibrahim:
You are trying to add String type into List vanzatorProduseList. You can add only VanzatorProduse type into vanzatorProduseList list. So, the cause of the problem is:
String num = elegantNumberButton.getNumber();
vanzatorProduseList.add(num);
You need to do something like this Create Object of your Custom class and assign value to that:
String num = elegantNumberButton.getNumber();
VanzatorProduse numVanProObject = new VanzatorProduse();
numVanProObject .setNumber(num );
vanzatorProduseList.add(numVanProObject );
But your custom call should have method to cater this type issue
Edit: Do not forget to call notifyDataSetChanged() method to refresh the list
VanzatorProduse producse = new VanzatorProduse();
producse.setProdus("add value here")
vanzatorProduseList.add(producse);
You are trying to add String type into List<VanzatorProduse> vanzatorProduseList. You can add only VanzatorProduse type into vanzatorProduseList list. So, the cause of the problem is:
String num = elegantNumberButton.getNumber();
vanzatorProduseList.add(num);
In your code you have following lines:
final VanzatorProduse vanzatorProduse = vanzatorProduseList.get(position);
textViewProdus1.setText(vanzatorProduse.getProdus());
textViewPret1.setText(vanzatorProduse.getPret());
So, might be you add num value into vanzatorProduse.setProdus(num) or any other appropriate field and then add it into the list:
vanzatorProduseList.add(vanzatorProduse);

Alertdialog with checkbox ( Don't show again )

I need to show an AlertDialog with "Don't Show Again" checkbox. I searched, but I couldn't find a working solution :/
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
PackageManager pk = getPackageManager();
Drawable icon;
alertDialogBuilder
.setTitle(R.string.confirm)
.setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
//Do something
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
If i'm not wrong then just Make one class extends with View.
public class DialogShow extends View {
SharedPreferences dialogPreferences;
String prefrencestring;
CheckBox nevershowagain;
Button closedialog;
Dialog dialog;
View view;
public DialogShow(final Context context) {
super(context);
dialog = new Dialog(context);
view = View.inflate(context, R.layout.startdialog, null);
dialog.setContentView(view);
nevershowagain = (CheckBox) view.findViewById(R.id.nevershowagain);
closedialog = (Button) view.findViewById(R.id.closedialog);
closedialog.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (nevershowagain.isChecked()) {
prefrencestring = "1";
dialogPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
Editor editprefrences = dialogPreferences.edit();
editprefrences.putString("showdialog", prefrencestring);
editprefrences.commit();
}
dialog.dismiss();
}
});
dialogPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
String check = dialogPreferences.getString("showdialog", "");
if (check.equals("1")) {
} else {
dialog.show();
}
}
}
Now call this class in your splash Activity on onCreate() method..
DialogShow d = new Dialog(this);
You can try this for AlertDialog :
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.myDialogLayout, null));
Dialog d = builder.create();
Edit: Please look into HERE FOR DETAILS EXPLANATION
Pass your view to the setView() method and it will set your view to the dialog body.
alertDialogBuilder.setView(your_view);
Since the accepted answer is not a good one in 2023 (IMO) and this post is the first one on google search, here is my solution:
private void showAlertWithCheck() {
boolean infoShowed = PreferenceManager.getDefaultSharedPreferences(this).
getBoolean(Const.PREF_KEY_INFO_SHOWN, false);
if (!infoShowed) {
View view = getLayoutInflater().inflate(R.layout.dialog_remember_check, null);
final CheckBox chk_drc_Remember = view.findViewById(R.id.chk_drc_Remember);
chk_drc_Remember.setText(R.string.dont_show_again);
chk_drc_Remember.setChecked(true);
new AlertDialog.Builder(MainActivity.this).
setIcon(android.R.drawable.ic_dialog_info).
setMessage(R.string.fixed_info).
setView(view).
setNeutralButton(R.string.caption_ok, null).
setOnDismissListener(dialog ->
PreferenceManager.getDefaultSharedPreferences(this).edit().
putBoolean(Const.PREF_KEY_INFO_SHOWN,
chk_drc_Remember.isChecked()).apply()).
show();
}
}
requied view XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical"
android:padding="#dimen/dialog_padding"
tools:context=".dialogs.PrayTimeDetailDialog"
tools:ignore="RtlHardcoded">
<CheckBox
android:id="#+id/chk_drc_Remember"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:paddingLeft="#dimen/dialog_padding"
android:paddingRight="#dimen/dialog_padding"
android:text="#string/remember_method" />

Java/Android: Change from one View (Intent) to another

Well, I was watching this tutorial:http://www.youtube.com/watch?v=9ew_Ajpqwqg#t=5m25s
Here you can see that he writes Intent i = new Intent......
But my app doesn't work like that :/
Here's my code
MainActivity.java
public class MainActivity extends Activity implements OnClickListener {
Button btnAddCategory, btnViewCategory;
EditText txtCategories;
TextView viewMain, viewAllCategories;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtCategories = (EditText) findViewById(R.id.txtCategories);
viewMain = (TextView) findViewById(R.id.viewMain);
btnAddCategory = (Button) findViewById(R.id.btnAddCategory);
btnViewCategory = (Button) findViewById(R.id.btnViewCategory);
viewAllCategories = (TextView) findViewById(R.id.viewAllCategories);
btnAddCategory.setOnClickListener(this);
btnViewCategory.setOnClickListener(this);
}
public void onClick(View arg0) {
switch(arg0.getId())
{
case R.id.btnAddCategory:
boolean didItWork = true;
try {
Categories entry = new Categories(MainActivity.this);
entry.open();
entry.createEntry(txtCategories.getText().toString());
entry.close();
} catch(Exception e) {
didItWork = false;
} finally {
if (didItWork)
{
Dialog d = new Dialog(MainActivity.this);
d.setTitle("New Category Created");
TextView tv = new TextView(MainActivity.this);
tv.setText("Success");
d.setContentView(tv);
d.show();
}
}
break;
case R.id.btnViewCategory:
Intent i = new Intent("android.intent.action.SQLVIEW");
startActivity(i);
break;
}
}
}
SQLView.Java
public class SQLView extends Activity {
protected void OnCreate(Bundle savedInstanceSatate) {
super.onCreate(savedInstanceSatate);
setContentView(R.layout.sqlview);
TextView tv = (TextView) findViewById(R.id.infosFromDb);
Categories info = new Categories(this);
info.open();
String data = info.getData();
info.close();
tv.setText(data);
} }
Manifest
<activity
android:name=".SQLView" android:label="#string/app_name">
<action android:name="android.intent.action.SQLVIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</activity>
I've read a thread here, where somebody was having the same problem, so I changed it to:
case R.id.btnViewCategory:
Intent i = new Intent(MainActivity.this, SQLView.class);
startActivity(i);
break;
So, now I don't get any exceptions, but I get an empty view. I can only see the name of my app, but that's it, all the TextViews etc. in the views are gone.
Is there anyone with an idea how to handle this?
Thanks in advance
Most of the times we write intents ,we miss some thing ,which takes time
I don't have Solution to your problem but i think its better than finding the missing part by watching the youtube video again and again.
Right Click on Project name for example : for Myandroidprojext
Myandroidprojext->new->other->Android Activity
This is the easy way to make new Activity without changing the Manifest Files or doing extrawork.

Categories

Resources