my UI isn't working (buttons) - java

I have an app and all of a sudden my user interface stopped working the share button works and also the options menu but for some odd reason my buttons stopped working they don't click or do anything . is it due to possibly the extending of my OptionsMenu class ? I have no idea why ? Does this happen often I tries to freshly build my project but no use . I have my MainActivity Class here
package com.mycompany.myapp;
import android.app.*;
import android.os.*;
import android.widget.Button;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.EditText;
import android.widget.AdapterView;
import android.widget.TextView;
import java.io.*;
import android.content.*;
import android.view.*;
import android.media.*;
import javax.security.auth.*;
import android.util.*;
import android.widget.AdapterView.*;
import java.net.*;
import org.apache.http.util.*;
import android.webkit.*;
import java.text.*;
import android.graphics.*;
import android.widget.TextView.*;
import android.text.*;
import android.widget.ActionMenuView.*;
import android.view.MenuItem.*;
import android.widget.*;
import android.content.Intent;
import android.net.*;
import java.util.*;
import java.nio.channels.*;
import java.nio.*;
import android.*;
public class MainActivity extends OptionsMenu
{
private MusicPlayer musicPlayer;
private String pos = "";
private FileManager fm;
private BlueTheme BlueTheme;
private PinkTheme PinkTheme;
private Downloader downloader;
private EditTextCustomizable etc;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
musicPlayer = new MusicPlayer(new MediaPlayer());
fm = new FileManager(this,this);
BlueTheme = new BlueTheme(this,this ,fm);
PinkTheme = new PinkTheme(this,this,fm);
etc = new EditTextCustomizable(this , BlueTheme , PinkTheme);
etc.customize();
Button rewind = (Button)findViewById(R.id.rewind);
rewind.setText("<");
Button fwd = (Button)findViewById(R.id.fwd);
fwd.setText(">");
ListView downloadsList = (ListView) findViewById(R.id.downloads);
downloadsList.setOnItemClickListener(new AdapterView.OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3){
ListView downloadsList = (ListView) findViewById(R.id.downloads);
pos = downloadsList.getItemAtPosition(position).toString();
musicPlayer.InitPlay(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + "/" + pos);
}});
}
public void Play(View view){
musicPlayer.Play();
EditText search = (EditText)findViewById(R.id.search);
musicPlayer.SearchResult(search.getText().toString());
}
public void Pause(View view){
musicPlayer.Pause();
}
public void Stop(View view){
musicPlayer.Stop();
}
public void Rewind(View view){
musicPlayer.Rewind();
}
public void Fwd(View view){
musicPlayer.Fwd();
}
public void onDownloadClick(View view){
EditText bar = (EditText)findViewById(R.id.search);
String downloadFile = bar.getText().toString();
downloader.DownloadURL(downloadFile);
}
}
And here is the OptionsMenu class where I am extending Activity note that I am not using AppCompatActivity .
package com.mycompany.myapp;
import android.view.*;
import android.app.*;
import android.net.*;
import java.util.*;
import android.widget.ListView;
import android.content.*;
import java.io.*;
import android.widget.*;
import android.*;
public class OptionsMenu extends Activity
{
private MusicPlayer musicPlayer;
private FileManager fm;
private BlueTheme blueTheme;
private PinkTheme pinkTheme;
private final int blue = Menu.FIRST;
private final int pink = blue + 1;
private int items = 0;
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
fm = new FileManager(this,this);
blueTheme = new BlueTheme(this,this,fm);
pinkTheme = new PinkTheme(this,this,fm);
fm.ListFiles();
menu.clear();
MenuInflater inflator = getMenuInflater();
inflator.inflate(R.menu.sidebar_menu, menu);
SubMenu subMenu = menu.addSubMenu("Themes");
subMenu.add(0 , blue , 0 , "Blue");
subMenu.add(0, pink , 1, "Pink");
items = subMenu.getItem().getItemId();
// tool bar menu
ArrayList<Uri> al = new ArrayList<Uri>();
ArrayList<Uri> emailAl = new ArrayList<Uri>();
MenuItem mi = menu.findItem(R.id.searchable);
MenuItem share = menu.findItem(R.id.share);
mi.setIcon(android.R.drawable.ic_search_category_default);
SearchView searchView = (SearchView) menu.findItem(R.id.searchable).getActionView();
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
ShareActionProvider sap = (ShareActionProvider) share.getActionProvider();
Intent intentShare = new Intent(Intent.ACTION_SEND_MULTIPLE);
Intent intentEmail = new Intent(Intent.ACTION_SEND_MULTIPLE);
intentShare.setType("audio/mp3");
intentEmail.setType("audio/mp3");
Uri uri = null;
Uri uriEmail = null;
//FileInputStream in = null;
//FileOutputStream out = null;
//try{
// for(File file : downloads){
// uri = Uri.fromFile(file);
// in = new FileInputStream(file);
// File outFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), file.getName()); // IMPORTANT! You need to create your file object separately, so you can then pass it to intent as well..
// out = new FileOutputStream(outFile);
// byte[] buf = new byte[1024];
// int len;
// while ( (len = in.read(buf, 0, buf.length)) != -1){
// out.write(buf, 0, len);
// }
// in.close();
// out.flush();
// out.close();
// uriEmail = Uri.fromFile(outFile); // Here you passed the parent directory file.. Pass newly created file object ..
// al.add(uri);
// emailAl.add(uriEmail);
// }
// } catch(IOException e){
// e.printStackTrace();
// }
//for(File file : fm.GetDownloadFiles()){
// uriEmail = Uri.fromFile(fm.exportFile(file));
//}
emailAl.add(uriEmail);
intentShare.putParcelableArrayListExtra(Intent.EXTRA_STREAM,al );
intentEmail.putParcelableArrayListExtra(Intent.EXTRA_STREAM,emailAl);
intentEmail.putExtra(Intent.EXTRA_SUBJECT , "Subject");
intentEmail.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sap.setShareIntent(intentShare);
sap.setShareIntent(intentEmail);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId()){
case R.id.playlist:
break;
case blue:
blueTheme.Blue();
break;
case pink:
pinkTheme.Pink();
break;
case R.id.muteoption:
musicPlayer.MuteVolume();
break;
case R.id.unmuteoption:
musicPlayer.UnMuteVolume();
break;
default:
return super.onOptionsItemSelected(item);
// TODO: Implement this method
}
return super.onOptionsItemSelected(item);
}
}
I can post up more code if requested. And will reedit if not clear enough thank you
EDITED
Here is the layout XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="4dp"
android:showAsAction="always"
android:windowActionBar="false"
android:theme="#android:style/Theme.Holo.Light"
/>
<TextView
android:id="#+id/downloadsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/downloadButton"
android:text="#string/downloadButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:onClick="onDownloadClick"
/>
<EditText
android:id="#+id/search"
android:hint="Do something"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/downloadButton"
android:background="#android:color/transparent"
android:paddingBottom="20dp"
android:paddingTop="20dp"/>
<Button
android:id="#+id/pause"
android:text="#string/pause"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="Pause"
android:layout_centerInParent="true"
android:layout_below="#id/search"
/>
<Button
android:id="#+id/play"
android:text="#string/play"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="Play"
android:layout_toRightOf="#id/pause"
android:layout_below="#id/search"/>
<Button
android:id="#+id/stop"
android:text="#string/stop"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="Stop"
android:layout_toLeftOf="#id/pause"
android:layout_below="#id/search"/>
<Button
android:id="#+id/rewind"
android:text="#string/rewind"
android:layout_height="wrap_content"
android:layout_width="50dp"
android:onClick="Rewind"
android:layout_toLeftOf="#id/stop"
android:layout_below="#id/search"/>
<Button
android:id="#+id/fwd"
android:text="#string/fwd"
android:layout_height="wrap_content"
android:layout_width="50dp"
android:onClick="Fwd"
android:layout_toRightOf="#id/play"
android:layout_below="#id/search"/>
<ListView
android:id="#+id/downloads"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rewind"
/>
</RelativeLayout>

Paste your layout xml if possible. I guess it's caused by something (maybe some parent view) interrupted the focus, so the child view button can't get focus.

Related

Programmatically loading parse images and text into linear layout

I am trying to create a list of items followed by their name and caloric value in a similar way to the image below.
However I am trying to do this while getting all my data from Parse. I have got it down for the most part but I have been stuck for hours trying to programatically add these two text views and image one after the other (text then view) as I loop through them.
I have been skeptical to make major changes to the code as I am not very proficient with android, however from what I have looked at so far my case seems to be unique in the sense that it involves both Parse and using textviews and imageviews together.
Below is what I've got so far on this activity:
XML
<?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="match_parent"
android:layout_height="match_parent"
tools:context=".AdminProductsListActivity">
<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="#+id/linLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
Class
package com.parse.starter;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.parse.FindCallback;
import com.parse.GetDataCallback;
import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
import java.util.List;
public class AdminProductsListActivity extends AppCompatActivity {
LinearLayout linLayout;
Intent intent;
String name;
TextView itemName;
TextView itemCalories;
ImageView imageView;
public void showMain() {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
public void addNewProduct() {
Intent intent = new Intent(getApplicationContext(), AddNewProductActivity.class);
intent.putExtra("shop", name);
startActivity(intent);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.new_admin_settings_menu, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.newItem){
ParseUser.logOut();
addNewProduct();
} else if (item.getItemId() == R.id.logout){
ParseUser.logOut();
showMain();
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_products_list);
intent = getIntent();
name = intent.getStringExtra("username");
linLayout = (LinearLayout) findViewById(R.id.linLayout);
setTitle(name);
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Product");
query.whereEqualTo("username", name);
query.orderByDescending("objectID");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if (e == null && list.size() > 0){
for (ParseObject object : list){
ParseFile file = (ParseFile) object.get("image");
//if (itemName != null && itemCalories != null){
itemName = new TextView(getApplicationContext());
itemName.setText(object.getString("name"));
itemName.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
itemCalories = new TextView(getApplicationContext());
itemCalories.setText(object.getString("calories") + " kcal");
itemCalories.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
linLayout.addView(itemCalories);
linLayout.addView(itemName);
file.getDataInBackground(new GetDataCallback() {
#Override
public void done(byte[] bytes, ParseException e) {
if (e == null && bytes != null){
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
imageView = new ImageView(getApplicationContext());
imageView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
));
imageView.setImageBitmap(bitmap);
linLayout.addView(imageView);
}
}
});
}
}
}
});
}
}
Right now what happens is all the text goes to the top and images goes to the bottom. I've also tried doing this:
file.getDataInBackground(new GetDataCallback() {
#Override
public void done(byte[] bytes, ParseException e) {
if (e == null && bytes != null){
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
imageView = new ImageView(getApplicationContext());
imageView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
));
imageView.setImageBitmap(bitmap);
linLayout.addView(imageView);
linLayout.addView(itemCalories);
linLayout.addView(itemName);
But then I get this Error:
The specified child already has a parent. You must call removeView() on the child's parent first.
and none of the answers to this error that I found seem to be helpful in this situation.
Long story short, I'm not even looking for something super complex or for it to look good, I am just a beginner. I just want to load the textviews and then the imageview one after the other, just like in the image, while using parse.
Any ideas?

Dynamically created Views don't appear in the GridLayout properly

I have a GridLayout in which I want dynamically generated TextViews to be displayed. At least the GridLayout can have 2 columns and at most it can have 3 columns.
I have a function called decide(int) that passes an integer argument to another function that actually generates the TextViews dynamically. This integer value is then tested to decide the number of columns and rows the GridLayout can have.
Following is my MainActivity.java
package accordiontry.juspay.accordiontry;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.GridLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private GridLayout gridLayout;
private final int FixedCol3 = 3, FixedCol2 = 2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
init();
handleClick();
decide(6);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void init()
{
gridLayout = (GridLayout) findViewById(R.id.gridLayout);
}
public void handleClick()
{
}
private void decide(int num)
{
if((num%3)==0 || (num%2)==0)
generateView(num);
else
{
num = num -1;
generateView(num);
}
}
public void generateView(int num)
{
if(((num%3)==0 && (num%2)==0) || (num%3)==0)
{
Toast.makeText(MainActivity.this,"3 has been executed", Toast.LENGTH_SHORT).show();
int number = num/3;
if(number>1)
{
gridLayout.setRowCount(number);
gridLayout.setColumnCount(FixedCol3);
createView(number*FixedCol3);
}
else
{
gridLayout.setRowCount(1);
gridLayout.setColumnCount(FixedCol3);
createView(number*FixedCol3);
}
}
else
{
Toast.makeText(MainActivity.this,"2 has been executed", Toast.LENGTH_SHORT).show();
int number = num/2;
if(number>1)
{
gridLayout.setRowCount(number);
gridLayout.setColumnCount(FixedCol2);
createView(number*FixedCol2);
}
else
{
gridLayout.setRowCount(1);
gridLayout.setColumnCount(FixedCol2);
createView(number*FixedCol2);
}
}
}
public void createView(int n)
{
for(int i=0;i<n;i++)
{
TextView tv = new TextView(this);
GridLayout.LayoutParams params = new GridLayout.LayoutParams();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
params.width = GridLayout.LayoutParams.MATCH_PARENT;
tv.setLayoutParams(params);
tv.setText("HEY THERE!!!");
gridLayout.addView(tv);
}
}
}
And following is my content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="accordiontry.juspay.accordiontry.MainActivity"
tools:showIn="#layout/activity_main">
<GridLayout
android:id="#+id/gridLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="129dp">
</GridLayout>
</RelativeLayout>
This is the output I'm getting: -
My app is supposed to generate 6 Hey There!! TextViews, but instead it ends up generating just 2.
Where am I going wrong?
Thank you for your time!!
Make your gridlayout's height to wrap_content.
<GridLayout
android:id="#+id/gridLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="129dp">
</GridLayout>
Found the solution myself.
Changing
params.width = GridLayout.LayoutParams.MATCH_PARENT;
to
params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
did the trick.

Not getting Text from EditText in custom Alert Builder View Layout

I am new to Android and building a simple To do List.
In a custom layout for an Alert Builder View, I want to retreive the user input in two EditText fields from this custom layout.
This is the custom view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView1"
android:layout_width="118dp"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/describe"
android:textColor="#A4C639" />
<EditText
android:id="#+id/task_description"
android:layout_width="155dp"
android:layout_height="wrap_content"
android:gravity="top|left"
android:inputType="textMultiLine|textAutoComplete|textAutoCorrect|textCapSentences"
android:lines="4"
android:minLines="2"
android:hint="#string/text_hint"
android:imeOptions="actionNext|actionDone"
android:scrollbars="horizontal" />
<requestFocus />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView2"
android:layout_width="118dp"
android:layout_height="92dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/when"
android:textColor="#A4C639" />
<EditText
android:id="#+id/task_date"
android:layout_width="155dp"
android:layout_height="wrap_content"
android:gravity="top|left"
android:inputType="date"
android:imeOptions="actionNext|actionDone"
android:scrollbars="horizontal" />
<requestFocus />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/task_relevance"
android:textColor="#A4C639" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_favourite"
/>
<!--
<Button
android:layout_width="64dp"
android:layout_height="wrap_content"
android:text="#string/save"
android:id="#+id/describetaskButton"
android:onClick="saveEntryClickFunction"
android:layout_weight="0.14" />-->
</LinearLayout>
</LinearLayout>
This is the Main Activity:
package com.example.TodoList;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import com.example.TodoList.db.TaskContract;
import com.example.TodoList.db.TaskDBHelper;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import static com.example.TodoList.R.id.task_description;
import static com.example.TodoList.db.TaskContract;
public class MainActivity extends ListActivity {
private ListAdapter listAdapter;
private TaskDBHelper helper;
private Toolbar toolbar;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final EditText inputField = new EditText(this);
builder.setNegativeButton("Abbrechen", null);
switch (item.getItemId()) {
case R.id.action_detail_task:
Intent TaskActivityIntent = new Intent(getApplicationContext(),
TaskActivity.class);
startActivity(TaskActivityIntent);
return true;
case R.id.action_add_task:
LayoutInflater inflater = (this).getLayoutInflater();
builder.setTitle("Eine Aufgabe hinzufügen");
builder.setMessage("Was möchten Sie erledigen? Bitte benennen Sie die Aufgabe");
builder.setView(R.layout.custom_view);
final View view=inflater.inflate(R.layout.custom_view, null);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
View v = (View) view.getParent();
final EditText taskDescription;
taskDescription = (EditText)view.findViewById(R.id.task_description);
taskDescription.getText().toString().trim();
Log.d("EditText TaskDate", taskDescription.getText().toString().trim());
final EditText taskDate;
taskDate = (EditText) view.findViewById(R.id.task_date);
taskDate.getText().toString().trim();
Log.d("EditText TaskDate", taskDate.getText().toString().trim());
final CheckBox taskFavourite;
taskFavourite = (CheckBox) view.findViewById(R.id.task_favourite);
if (taskFavourite.isChecked()) {
helper = new TaskDBHelper(MainActivity.this);
SQLiteDatabase db = helper.getWritableDatabase();
ContentValues values = new ContentValues();
values.clear();
values.put(Columns.FAVOURITE, String.valueOf(taskFavourite));
db.insertWithOnConflict(TaskContract.TABLE, null, values, SQLiteDatabase.CONFLICT_IGNORE);
} else {
Log.d("Task Activity", "Checkbox is not checked");
}
Log.d("Task Text", taskDescription.getText().toString().trim());
Log.d("Task Date", taskDate.getText().toString().trim());
helper = new TaskDBHelper(MainActivity.this);
SQLiteDatabase db = helper.getWritableDatabase();
ContentValues values = new ContentValues();
values.clear();
values.put(TaskContract.Columns.TASK_DESCRIPTION, task_description);
values.put(Columns.DATE, String.valueOf(taskDate));
//values.put(Columns.FAVOURITE, String.valueOf(taskFavourite));
db.insertWithOnConflict(TaskContract.TABLE, null, values, SQLiteDatabase.CONFLICT_IGNORE);
updateUI();
db.close();
}
});
builder.create().show();
return true;
case R.id.action_remove_task:
builder.setTitle("Eine Aufgabe entfernen");
builder.setMessage("Wurde die Aufgabe bereits erledigt?");
View checkBoxView = View.inflate(this, R.layout.checkbox, null);
CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkbox);
builder.setView(checkBoxView);
builder.setNegativeButton("Entfernen", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
String task = inputField.getText().toString();
String sql = String.format("DELETE FROM %s WHERE %s = '%s'",
TABLE,
Columns.TASK,
Columns.TASK_DESCRIPTION,
Columns.TASK_STATUS,
Columns.DATE,
Columns.FAVOURITE,
task);
helper = new TaskDBHelper(MainActivity.this);
SQLiteDatabase sqlDB = helper.getWritableDatabase();
sqlDB.execSQL(sql);
sqlDB.close();
updateUI();
}
});
builder.create().show();
return true;
default:
return false;
}
}
public void onDoneCheckBoxClick(View view) {
Log.d("onDoneCheckBoxClick", "First Check Box Click Function");
View v = (View) view.getParent();
TextView taskTextView = (TextView) v.findViewById(R.id.taskTextView);
helper = new TaskDBHelper(MainActivity.this);
SQLiteDatabase sqlDB = helper.getWritableDatabase();
String task = taskTextView.getText().toString();
String sql = String.format("DELETE FROM %s WHERE %s = '%s'",
TABLE,
TaskContract.Columns.TASK,
task);
sqlDB.execSQL(sql);
sqlDB.close();
updateUI();
}
public void DetailClick(View view) {
Intent TaskActivityIntent = new Intent(getApplicationContext(),
TaskActivity.class);
startActivity(TaskActivityIntent);
}
private void updateUI() {
helper = new TaskDBHelper(MainActivity.this);
SQLiteDatabase sqlDB = helper.getReadableDatabase();
Cursor cursor = sqlDB.query(TABLE,
new String[]{Columns._ID, Columns.TASK, Columns.DATE,
Columns.TASK_STATUS
},
null, null, null, null, null
);
listAdapter = new SimpleCursorAdapter(
this,
R.layout.task_view,
cursor,
new String[]{Columns.TASK, Columns.DATE, Columns.TASK_STATUS},
new int[]{R.id.taskTextView,R.id.taskDateView,R.id.task_favourite},
0
);
this.setListAdapter(listAdapter);
}
public void onDetailViewClick(View view) {
Intent TaskActivityIntent = new Intent(getApplicationContext(),
TaskActivity.class);
startActivity(TaskActivityIntent);
}
#Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app deep link URI is correct.
Uri.parse("android-app://com.example.TodoList/http/host/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}
#Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app deep link URI is correct.
Uri.parse("android-app://com.example.TodoList/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
}
I am not receiving any logged input from the EditText in the logcat.
Any hints or help would be very appreciated!
You're using a view that is different from the one that's in the dialog.
Try casting the dialogInterface to Dialog:
taskDescription = (EditText) ((Dialog) dialogInterface).findViewById(R.id.task_description);

Form displays nothing when debugging android in Eclipse

The form for viewing has textviews, a listview and a button, but it only display a white blank form during debugging.
view_dates_e.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/view_e"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="14dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView2" >
</ListView>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Add Expense" />
</RelativeLayout>
ViewExpenseDate.java:
package com.example.expensetracker1;
import com.example.expensetracker1.helper.SchemaHelper;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class ViewExpenseDate extends Activity implements OnClickListener{
Button GoBton;
public void ViewExpDate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_dates_e);//to change
Bundle bundle = getIntent().getExtras();
String date4,cat_a = null,cat_b = null,cat_c = null,cat_d = null,cat_e = null,cat_f=null;
int a1=0,b1=0,c1=0,d1=0,e1=0,f1=0;
SchemaHelper sh = new SchemaHelper(this);
TextView txt1 = (TextView)findViewById(R.id.textView1);
TextView txt2 = (TextView)findViewById(R.id.textView2);
date4 = bundle.getString("Date");
Toast msg2 = Toast.makeText(getApplicationContext(),"Selected Date : \n"+date4,Toast.LENGTH_SHORT);
msg2.show();
txt1.setText("Today's Expenses : " + date4);
Cursor c = sh.getDetails(date4);
while (c.moveToNext()){
int Cat = c.getColumnIndex(DetailsTable.C_ID);
int Amt = c.getColumnIndex(DetailsTable.E_Amt);
int ader = c.getColumnIndex(DetailsTable.O_NAME);
if(Cat==1){
a1 = a1+Amt;
cat_a = "Foods: \n"+a1;
}else if(Cat==2){
b1 = b1+Amt;
cat_b = "Fares: \n"+b1;
}else if(Cat==3){
c1 = c1+Amt;
cat_c = "Bills: \n"+c1;
}else if(Cat==4){
d1 = d1+Amt;
cat_d = "Personal Needs: \n"+d1;
}else if(Cat == 5){
cat_e = "Fares: \n"+e1;
};
cat_f=cat_a+"\n"+cat_b+"\n"+cat_c+"\n"+cat_d+"\n"+cat_e+"\n";
txt2.setText(cat_f);
}
GoBton = (Button)findViewById(R.id.button1);
GoBton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent view_e = new Intent(v.getContext(),Input_Expense.class);
startActivity(view_e);
}
});
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
And, this is the activity before the ViewExpenseDate.java,
Expense_Calendar.java
package com.example.expensetracker1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.Time;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
public class Expense_Calendar extends Activity implements OnClickListener,OnDateChangedListener{
Button GoBtn;
DatePicker datepick ;
int date1,date2,date3;
Bundle bun = new Bundle();
Time today;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.expense_calendar_layout);
today = new Time(Time.getCurrentTimezone());
today.setToNow();
Toast msg2 = Toast.makeText(getApplicationContext(),"Current Date \n"+(today.month+1)+"/"+today.monthDay+"/"+today.year,Toast.LENGTH_LONG);
msg2.show();
//now.set(2015, 1, 12);
datepick = (DatePicker)findViewById(R.id.datePicker1);
GoBtn = (Button)findViewById(R.id.button1);
GoBtn.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
date1 = datepick.getMonth() + 1;
date2 = datepick.getDayOfMonth();
date3 = datepick.getYear();
int now1 = today.month + 1; //d.MONTH;
int now2 = today.monthDay; //d.DATE;
int now3 = today.year; //d.YEAR;
//converting dates into string
String now4 = now1+"/"+now2+"/"+now3;
String date4 = date1+"/"+date2+"/"+date3;
SimpleDateFormat dateFormat= new SimpleDateFormat("MM/dd/yyyy");
Date convDate1 = new Date();
Date convDate2 = new Date();
try {
convDate1 = dateFormat.parse(now4);
convDate2 = dateFormat.parse(date4);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (convDate1.equals(convDate2)){
Intent i = new Intent(v.getContext(),ViewExpenseDate.class);
bun.putString("Date", date4);
i.putExtras(bun);
startActivity(i);
}else if (convDate1.after(convDate2)){
Intent e = new Intent(v.getContext(),ViewExpensePerDate.class);
bun.putString("Date", date4);
e.putExtras(bun); //Pasa ang Date sa Ibang Form
startActivity(e);
}else if ( convDate1.before(convDate2)){
Intent r = new Intent(v.getContext(),ViewReminderDate.class);
bun.putString("Date", date4);
r.putExtras(bun);
startActivity(r);
}
}
});
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
#Override
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
}
}
The display of the xml file for Expense_Calendar.java displays just fine during debugging, but upon "if(convDate1.equals(convDate2))" condition is true, the form view_date_e.xml displays next should have some textviews, a listview and a button displaying, but it only displays a blank form.
Any help would be greatly much appreciated

android - Toolbar not displaying in activity

working on a wallpaper app and working on moving to API 21 and removing the ActionBar in favor of Toolbar. That being said, I am trying to use the v7-support library. What happens is basically there is a grey outline of where the toolbar should be, but it never appears.
WallpaperActivity.java:
package com.death2all110.blisspapers;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.koushikdutta.urlimageviewhelper.UrlImageViewCallback;
import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
public class WallpaperActivity extends ActionBarActivity {
public final String TAG = "BlissPapers";
protected static final String MANIFEST = "wallpaper_manifest.xml";
protected static final int THUMBS_TO_SHOW = 4;
/*
* pull the manifest from the web server specified in config.xml or pull
* wallpaper_manifest.xml from local assets/ folder for testing
*/
public static final boolean USE_LOCAL_MANIFEST = false;
ArrayList<WallpaperCategory> categories = null;
ProgressDialog mLoadingDialog;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(getResources().getColor(R.color.primary_dark));
setContentView(R.layout.activity_wallpaper);
mLoadingDialog = new ProgressDialog(this);
mLoadingDialog.setCancelable(false);
mLoadingDialog.setIndeterminate(true);
mLoadingDialog.setMessage("Retreiving wallpapers from server...");
mLoadingDialog.show();
new LoadWallpaperManifest().execute();
Toolbar ab = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(ab);
getSupportActionBar().setTitle("Bliss Papers");
getSupportActionBar().setDisplayShowTitleEnabled(true);
UrlImageViewHelper.setErrorDrawable(getResources().getDrawable(com.death2all110.blisspapers.R.drawable.ic_error));
}
#Override
public void onResume() {
super.onResume();
Wallpaper.wallpapersCreated = 0;
}
protected void loadPreviewFragment() {
WallpaperPreviewFragment fragment = new WallpaperPreviewFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.add(android.R.id.content, fragment);
ft.commit();
}
public static class WallpaperPreviewFragment extends Fragment {
static final String TAG = "PreviewFragment";
WallpaperActivity mActivity;
View mView;
public int currentPage = -1;
public int highestExistingIndex = 0;
Button back;
Button next;
TextView pageNum;
ThumbnailView[] thumbs;
protected int selectedCategory = 0; // *should* be <ALL> wallpapers
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mActivity = (WallpaperActivity) getActivity();
next(); // load initial page
}
public void setCategory(int cat) {
selectedCategory = cat;
currentPage = -1;
next();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mView = inflater.inflate(com.death2all110.blisspapers.R.layout.activity_wallpaper, container, false);
back = (Button) mView.findViewById(com.death2all110.blisspapers.R.id.backButton);
next = (Button) mView.findViewById(com.death2all110.blisspapers.R.id.nextButton);
pageNum = (TextView) mView.findViewById(com.death2all110.blisspapers.R.id.textView1);
thumbs = new ThumbnailView[THUMBS_TO_SHOW];
thumbs[0] = (ThumbnailView) mView.findViewById(com.death2all110.blisspapers.R.id.imageView1);
thumbs[1] = (ThumbnailView) mView.findViewById(com.death2all110.blisspapers.R.id.imageView2);
thumbs[2] = (ThumbnailView) mView.findViewById(com.death2all110.blisspapers.R.id.imageView3);
thumbs[3] = (ThumbnailView) mView.findViewById(com.death2all110.blisspapers.R.id.imageView4);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
next();
}
});
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
previous();
}
});
return mView;
}
public ArrayList<WallpaperCategory> getCategories() {
return mActivity.categories;
}
protected Wallpaper getWallpaper(int realIndex) {
return getCategories().get(selectedCategory).getWallpapers().get(realIndex);
}
protected void setThumbs() {
for (ThumbnailView v : thumbs)
v.setVisibility(View.INVISIBLE);
final int numWallpapersInCategory = getCategories().get(selectedCategory)
.getWallpapers().size();
boolean enableForward = true;
for (int i = 0; i < thumbs.length; i++) {
final int realIndex = (currentPage * thumbs.length + i);
if (realIndex >= (numWallpapersInCategory - 1)) {
enableForward = false;
break;
}
Wallpaper w = getWallpaper(realIndex);
thumbs[i].setOnClickListener(null);
thumbs[i].getName().setText(w.getName());
thumbs[i].getAuthor().setText(w.getAuthor());
UrlImageViewHelper.setUrlDrawable(thumbs[i].getThumbnail(), w.getThumbUrl(),
com.death2all110.blisspapers.R.drawable.ic_placeholder, new ThumbnailCallBack(w, realIndex));
}
back.setEnabled(currentPage != 0);
next.setEnabled(enableForward);
}
public void next() {
getNextButton().setEnabled(false);
pageNum.setText(getResources().getString(com.death2all110.blisspapers.R.string.page) + " " + (++currentPage + 1));
setThumbs();
}
public void previous() {
pageNum.setText(getResources().getString(com.death2all110.blisspapers.R.string.page) + " " + (--currentPage + 1));
setThumbs();
}
protected void skipToPage(int page) {
if (page < currentPage) {
while (page < currentPage) {
previous(); // should subtract page
}
} else if (page > currentPage) {
while (page > currentPage) {
next();
}
}
}
public void jumpTo() {
// View view = getLayoutInflater().inflate(R.layout.dialog_jumpto,
// null);
// final EditText e = (EditText) view.findViewById(R.id.pageNumber);
// AlertDialog.Builder j = new AlertDialog.Builder(this);
// j.setTitle(R.string.jump2);
// j.setView(view);
// j.setPositiveButton(android.R.string.ok, new
// DialogInterface.OnClickListener() {
//
// public void onClick(DialogInterface dialog, int which) {
// skipToPage(Integer.parseInt(e.getText().toString()));
// }
// });
// j.setNegativeButton(android.R.string.no, new
// DialogInterface.OnClickListener() {
//
// public void onClick(DialogInterface dialog, int which) {
// dialog.cancel();
// }
// });
// j.create().show();
}
protected View getThumbView(int i) {
if (thumbs != null && thumbs.length > 0)
return thumbs[i];
else
return null;
}
protected Button getNextButton() {
return next;
}
protected Button getPreviousButton() {
return back;
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case com.death2all110.blisspapers.R.id.jump:
jumpTo();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
class ThumbnailCallBack implements UrlImageViewCallback {
Wallpaper wall;
int index;
public ThumbnailCallBack(Wallpaper wall, int index) {
this.wall = wall;
this.index = index;
}
#Override
public void onLoaded(ImageView imageView, Drawable loadedDrawable, String url,
boolean loadedFromCache, boolean error) {
final int relativeIndex = index % 4;
if (!error) {
getThumbView(relativeIndex).setOnClickListener(
new ThumbnailClickListener(wall));
}
getThumbView(relativeIndex).setVisibility(View.VISIBLE);
if (relativeIndex == 3)
getNextButton().setEnabled(true);
}
}
class ThumbnailClickListener implements View.OnClickListener {
Wallpaper wall;
public ThumbnailClickListener(Wallpaper wallpaper) {
this.wall = wallpaper;
}
#Override
public void onClick(View v) {
Intent preview = new Intent(mActivity, Preview.class);
preview.putExtra("wp", wall.getUrl());
startActivity(preview);
}
}
}
public static String getDlDir(Context c) {
String configFolder = getResourceString(c, com.death2all110.blisspapers.R.string.config_wallpaper_download_loc);
if (configFolder != null && !configFolder.isEmpty()) {
return new File(Environment.getExternalStorageDirectory(), configFolder)
.getAbsolutePath() + "/";
} else {
return Environment.getExternalStorageDirectory().getAbsolutePath();
}
}
public static String getSvDir(Context c) {
String configFolder = getResourceString(c, com.death2all110.blisspapers.R.string.config_wallpaper_sdcard_dl_location);
if (configFolder != null && !configFolder.isEmpty()) {
return new File(Environment.getExternalStorageDirectory(), configFolder)
.getAbsolutePath() + "/";
} else {
return null;
}
}
protected String getWallpaperDestinationPath() {
String configFolder = getResourceString(com.death2all110.blisspapers.R.string.config_wallpaper_sdcard_dl_location);
if (configFolder != null && !configFolder.isEmpty()) {
return new File(Environment.getExternalStorageDirectory(), configFolder)
.getAbsolutePath();
}
// couldn't find resource?
return null;
}
protected String getResourceString(int stringId) {
return getApplicationContext().getResources().getString(stringId);
}
public static String getResourceString(Context c, int id) {
return c.getResources().getString(id);
}
private class LoadWallpaperManifest extends
AsyncTask<Void, Boolean, ArrayList<WallpaperCategory>> {
#Override
protected ArrayList<WallpaperCategory> doInBackground(Void... v) {
try {
InputStream input = null;
if (USE_LOCAL_MANIFEST) {
input = getApplicationContext().getAssets().open(MANIFEST);
} else {
URL url = new URL(getResourceString(com.death2all110.blisspapers.R.string.config_wallpaper_manifest_url));
URLConnection connection = url.openConnection();
connection.connect();
// this will be useful so that you can show a typical
// 0-100%
// progress bar
int fileLength = connection.getContentLength();
// download the file
input = new BufferedInputStream(url.openStream());
}
OutputStream output = getApplicationContext().openFileOutput(
MANIFEST, MODE_PRIVATE);
byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
// publishProgress((int) (total * 100 / fileLength));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
// file finished downloading, parse it!
ManifestXmlParser parser = new ManifestXmlParser();
return parser.parse(new File(getApplicationContext().getFilesDir(), MANIFEST),
getApplicationContext());
} catch (Exception e) {
Log.d(TAG, "Exception!", e);
}
return null;
}
#Override
protected void onPostExecute(ArrayList<WallpaperCategory> result) {
categories = result;
if (categories != null)
loadPreviewFragment();
mLoadingDialog.cancel();
super.onPostExecute(result);
}
}
}
Here is activity_wallpaper.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:id="#+id/strut"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/backButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignRight="#id/strut"
android:layout_marginBottom="5dp"
android:text="#string/back" />
<Button
android:id="#+id/nextButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/strut"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:text="#string/next" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/backButton"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:text="#string/page" />
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/textView1"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/actionBarSize"
android:background="?android:attr/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<com.death2all110.blisspapers.ThumbnailView
android:id="#+id/imageView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1" />
<com.death2all110.blisspapers.ThumbnailView
android:id="#+id/imageView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<com.death2all110.blisspapers.ThumbnailView
android:id="#+id/imageView3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1" />
<com.death2all110.blisspapers.ThumbnailView
android:id="#+id/imageView4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
styles.xml:
<resources>
<style name="Theme.Bliss" parent="Theme.AppCompat.NoActionBar">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/accent</item>
</style>
</resources>
If I remove the setContentView from the onCreate method, I get an error:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.support.v7.widget.Toolbar.getTitle()' on a null object reference
Any ideas on what I can do to correct this?
Screenshot:
You need to add a android.supprt.v7.widget.Toolbar to your layout and then do this in the onCreate method of your ActionBarActivity
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActitionBar(toolbar);
Also, make sure your theme uses Theme.AppCompat.NoActionBar (or Theme.AppCompat.Light.NoActionBar)
FWIW - i just retrofitted some ABS stuff to the newer Toolbar stuff that you are on and had some issues with the Title not showing up in all Frgments, activities.... Some worked some did not. Very frustrating to have varied outcomes. Had to replicate the following code in places where i did not think it should be needed due to inheritance and due to calls to 'super.onCreate()'..
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
After populated the above code everywhere in those activities/frags where it did NOT show up, the issue resolved.
Really odd that ur title flashes up then disappear.. something is repainting the view!
I found out that I needed to
<include layout="#layout/toolbar_layout"/>
in my activity's layout file since I had my toolbar layout defined in its own xml file.

Categories