Form displays nothing when debugging android in Eclipse - java

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

Related

Android Studio E/AndroidRuntime: FATAL EXCEPTION: main [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
this ERROR came after i was modifying those click listeners
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.apple.sqlite, PID: 31591
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.apple.sqlite/com.example.apple.sqlite.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setKeyListener(android.text.method.KeyListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setKeyListener(android.text.method.KeyListener)' on a null object reference
at com.example.apple.sqlite.MainActivity.onCreate(MainActivity.java:46)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
MainActivity.java code
package com.example.apple.sqlite;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private Calendar calendar;
private TextView dateView;
private int year, month, day;
private ListView obj;
DBHelper mydb;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mydb = new DBHelper(this);
ArrayList array_list = mydb.getAllCotacts();
ArrayAdapter arrayAdapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1, array_list);
dateView = (TextView) findViewById(R.id.SQDate);
dateView.setKeyListener(null);
Button dateButton = (Button)findViewById(R.id.DateButton);
calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
day = calendar.get(Calendar.DAY_OF_MONTH);
showDate(year, month+1, day);
dateButton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int month, int day) {
String format = getString(R.string.setdate) + setDateFormat(year,month,day);
dateView.setText(format);
}
}, year,month, day).show();
}
});
obj = (ListView)findViewById(R.id.listView1);
obj.setAdapter(arrayAdapter);
obj.setOnItemClickListener(new AdapterView.OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
// TODO Auto-generated method stub
int id_To_Search = arg2 + 1;
Bundle dataBundle = new Bundle();
dataBundle.putInt("id", id_To_Search);
Intent intent = new Intent(getApplicationContext(),DisplayContact.class);
intent.putExtras(dataBundle);
startActivity(intent);
}
});
}
private String setDateFormat(int year,int monthOfYear,int dayOfMonth){
return String.valueOf(year) + "-"
+ String.valueOf(monthOfYear + 1) + "-"
+ String.valueOf(dayOfMonth);
}
public void setDate(View view) {
showDialog(999);
Toast.makeText(getApplicationContext(), "ca",
Toast.LENGTH_SHORT)
.show();
}
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
if (id == 999) {
return new DatePickerDialog(this,
myDateListener, year, month, day);
}
return null;
}
private DatePickerDialog.OnDateSetListener myDateListener = new
DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker arg0,
int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
// arg1 = year
// arg2 = month
// arg3 = day
showDate(arg1, arg2+1, arg3);
}
};
private void showDate(int year, int month, int day) {
dateView.setText(new StringBuilder().append(year).append("-")
.append(month).append("-").append(day));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item){
super.onOptionsItemSelected(item);
switch(item.getItemId()) {
case R.id.item1:Bundle dataBundle = new Bundle();
dataBundle.putInt("id", 0);
Intent intent = new Intent(getApplicationContext(),DisplayContact.class);
intent.putExtras(dataBundle);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public boolean onKeyDown(int keycode, KeyEvent event) {
if (keycode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(true);
}
return super.onKeyDown(keycode, event);
}
}
DisplayContact.java code
package com.example.apple.sqlite;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
/**
* Created by Apple on 2017/3/5.
*/
public class DisplayContact extends Activity {
int from_Where_I_Am_Coming = 0;
private DBHelper mydb ;
TextView date ;
TextView item;
TextView describe;
TextView money;
int id_To_Update = 0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_contact);
date = (TextView) findViewById(R.id.SQDate);
item = (TextView) findViewById(R.id.SQItem);
describe = (TextView) findViewById(R.id.SQDescribe);
money = (TextView) findViewById(R.id.SQMoney);
mydb = new DBHelper(this);
Bundle extras = getIntent().getExtras();
if(extras !=null) {
int Value = extras.getInt("id");
if(Value>0){
//means this is the view part not the add contact part.
Cursor rs = mydb.getData(Value);
id_To_Update = Value;
rs.moveToFirst();
String xdate = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_DATE));
String xitem = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_ITEM));
String xdescribe = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_DESCRIBE));
String xmoney = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_MONEY));
if (!rs.isClosed()) {
rs.close();
}
Button b = (Button)findViewById(R.id.EnterButton);
b.setVisibility(View.INVISIBLE);
date.setText((CharSequence)xdate);
date.setFocusable(false);
date.setClickable(false);
item.setText((CharSequence)xitem);
item.setFocusable(false);
item.setClickable(false);
describe.setText((CharSequence)xdescribe);
describe.setFocusable(false);
describe.setClickable(false);
money.setText((CharSequence)xmoney);
money.setFocusable(false);
money.setClickable(false);
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
Bundle extras = getIntent().getExtras();
if(extras !=null) {
int Value = extras.getInt("id");
if(Value>0){
getMenuInflater().inflate(R.menu.display_contact, menu);
} else{
getMenuInflater().inflate(R.menu.main_menu, menu);
}
}
return true;
}
public boolean onOptionsItemSelected(MenuItem items) {
super.onOptionsItemSelected(items);
switch(items.getItemId()) {
case R.id.Edit_Contact:
Button b = (Button)findViewById(R.id.EnterButton);
b.setVisibility(View.VISIBLE);
date.setEnabled(true);
date.setFocusableInTouchMode(true);
date.setClickable(true);
item.setEnabled(true);
item.setFocusableInTouchMode(true);
item.setClickable(true);
describe.setEnabled(true);
describe.setFocusableInTouchMode(true);
describe.setClickable(true);
money.setEnabled(true);
money.setFocusableInTouchMode(true);
money.setClickable(true);
return true;
case R.id.Delete_Contact:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.deleteContact)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mydb.deleteContact(id_To_Update);
Toast.makeText(getApplicationContext(), "Deleted Successfully",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
AlertDialog d = builder.create();
d.setTitle("Are you sure");
d.show();
return true;
default:
return super.onOptionsItemSelected(items);
}
}
/*public void run(View view) {
Bundle extras = getIntent().getExtras();
if(extras !=null) {
int Value = extras.getInt("id");
if(Value>0){
if(mydb.updateContact(id_To_Update,date.getText().toString(),
item.getText().toString(), describe.getText().toString(),
money.getText().toString())){
Toast.makeText(getApplicationContext(), "Updated", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
} else{
Toast.makeText(getApplicationContext(), "not Updated", Toast.LENGTH_SHORT).show();
}
} else{
if(mydb.insertContact(date.getText().toString(), item.getText().toString(),
describe.getText().toString(), money.getText().toString())){
Toast.makeText(getApplicationContext(), "done",
Toast.LENGTH_SHORT).show();
} else{
Toast.makeText(getApplicationContext(), "not done",
Toast.LENGTH_SHORT).show();
}
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
}
}
}*/
}
DBHelper.java code
package com.example.apple.sqlite;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
/**
* Created by Apple on 2017/3/4.
*/
public class DBHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "MyDBName.db";
public static final String CONTACTS_TABLE_NAME = "contacts";
public static final String CONTACTS_COLUMN_ID = "id";
public static final String CONTACTS_COLUMN_DATE = "date";
public static final String CONTACTS_COLUMN_ITEM = "item";
public static final String CONTACTS_COLUMN_DESCRIBE = "describe";
public static final String CONTACTS_COLUMN_MONEY = "money";
public DBHelper(Context context) {
super(context, DATABASE_NAME , null, 1);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE contacts " +
"(_id INTEGER PRIMARY KEY NOT NULL , " +
"date DATETIME NOT NULL , " +
"item VARCHAR, " +
"describe VARCHAR," +
"money INTEGER)"
);
}
public boolean insertContact (String date, String item, String describe, String money) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("date", date);
contentValues.put("item", item);
contentValues.put("describe", describe);
contentValues.put("money", money);
db.insert("contacts", null, contentValues);
return true;
}
public Cursor getData(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery( "select * from contacts where id="+id+"", null );
return res;
}
public int numberOfRows(){
SQLiteDatabase db = this.getReadableDatabase();
int numRows = (int) DatabaseUtils.queryNumEntries(db, "contacts");
return numRows;
}
public boolean updateContact (Integer id, String date, String item, String describe, String money) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("date", date);
contentValues.put("item", item);
contentValues.put("describe", describe);
contentValues.put("money", money);
db.update("contacts", contentValues, "id = ? ", new String[] { Integer.toString(id) } );
return true;
}
public Integer deleteContact (Integer id) {
SQLiteDatabase db = this.getWritableDatabase();
return db.delete("contacts",
"id = ? ",
new String[] { Integer.toString(id) });
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS contacts");
onCreate(db);
}
public ArrayList<String> getAllCotacts() {
ArrayList<String> array_list = new ArrayList<String>();
//hp = new HashMap();
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery( "select * from contacts", null );
res.moveToFirst();
while(res.isAfterLast() == false){
array_list.add(res.getString(res.getColumnIndex("contacts")));
res.moveToNext();
}
return array_list;
}
}
I reference two web and created this project
http://www.tutorialspoint.com/android/android_sqlite_database.htm
https://www.tutorialspoint.com/android/android_datepicker_control.htm
How can I do?
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30sp"
android:text="#string/DataBase" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
</ListView>
</RelativeLayout>
activity_display_contact.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/enter"
android:textSize="26sp"
android:textStyle="normal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/item" />
<EditText
android:id="#+id/SQItem"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint=""/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/describe" />
<EditText
android:id="#+id/SQDescribe"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint=""/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/money" />
<EditText
android:id="#+id/SQMoney"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint=""/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/date" />
<EditText
android:id="#+id/SQDate"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint=""/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/EnterButton"
style="#style/AppTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/news" />
<Button
android:id="#+id/DateButton"
style="#style/AppTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/choose" />
<Button
android:id="#+id/CancelButton"
style="#style/AppTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cancel" />
</LinearLayout>
</LinearLayout>
In your layout activity_main.xml, is there any TextView with android:id="#+id/SQDate"?
I guess you are trying to call that TextView from another .xml
Edited:
Your View that has ID = SQDate is not a TextView, it is an EditText.
In your MainActivity class, change this:
private TextView dateView;
and
dateView = (TextView) findViewById(R.id.SQDate);
To:
private EditText dateView;
and
dateView = (EditText) findViewById(R.id.SQDate);
change your TextView Id to SQDate in activity_main.xml
Replace :
android:id="#+id/textView"
With:
android:id="#+id/SQDate"

cannot resolve symbol HorizontalListView

I am trying to declare a horizontal listview in my activity like this
private LinearLayout lay;
HorizontalListView listview;
however the HorizontalListView is highlighted in red and I get the error "Cannot resolve symbol HorizontalListView "
Java File
package com.xera.deviceinsight.home;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class SensorCharts extends Activity{
private LinearLayout lay;
HorizontalListView listview;
private double highest;
private int[] grossheight;
private int[] netheight;
private Double[] grossSal= {15000.0,15000.0,15000.25,15000.1,
15000.0,15000.0,15000.0,15000.0,
15000.25,15000.1,15000.0,15000.0};
private Double[] netSal = {12000.0,13000.0,14000.25,10000.1,
10000.0,9000.0,12000.0,13000.0,
14000.25,10000.1,10000.0,9000.0};
private String[] datelabel = {"Jan 12","Feb 12","Mar 12",
"Apr 12","May 12","Jun 12",
"Jul 12","Aug 12","Sep 12",
"Oct 12","Nov 12","Dec 12"};
public void onCreate(Bundle savedInstance)
{
super.onCreate(savedInstance);
setContentView(R.layout.main);
lay = (LinearLayout)findViewById(R.id.linearlay);
listview = (HorizontalListView) findViewById(R.id.listview);
List<Double> b = Arrays.asList(grossSal);
highest = (Collections.max(b));
netheight = new int[netSal.length];
grossheight= new int[grossSal.length];
//updateSizeInfo();
}
public class bsAdapter extends BaseAdapter
{
Activity cntx;
String[] array;
public bsAdapter(Activity context,String[] arr)
{
// TODO Auto-generated constructor stub
this.cntx=context;
this.array = arr;
}
public int getCount()
{
// TODO Auto-generated method stub
return array.length;
}
public Object getItem(int position)
{
// TODO Auto-generated method stub
return array[position];
}
public long getItemId(int position)
{
// TODO Auto-generated method stub
return array.length;
}
public View getView(final int position, View convertView, ViewGroup parent)
{
View row=null;
LayoutInflater inflater=cntx.getLayoutInflater();
row=inflater.inflate(R.layout.list, null);
DecimalFormat df = new DecimalFormat("#.##");
final TextView title = (TextView)row.findViewById(R.id.title);
TextView tvcol1 = (TextView)row.findViewById(R.id.colortext01);
TextView tvcol2 = (TextView)row.findViewById(R.id.colortext02);
TextView gt = (TextView)row.findViewById(R.id.text01);
TextView nt = (TextView)row.findViewById(R.id.text02);
tvcol1.setHeight(grossheight[position]);
tvcol2.setHeight(netheight[position]);
title.setText(datelabel[position]);
gt.setText(df.format(grossSal[position]/1000)+" k");
nt.setText(df.format(netSal[position]/1000)+" k");
tvcol1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(SensorCharts.this, "Month/Year: "+title.getText().toString()+"\nGross Sal: "+grossSal[position], Toast.LENGTH_SHORT).show();
}
});
tvcol2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(SensorCharts.this, "Month/Year: "+title.getText().toString()+"\nNet Sal: "+netSal[position], Toast.LENGTH_SHORT).show();
}
});
return row;
}
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
updateSizeInfo();
}
private void updateSizeInfo() {
/** This is onWindowFocusChanged method is used to allow the chart to
* update the chart according to the orientation.
* Here h is the integer value which can be updated with the orientation
*/
int h;
if(getResources().getConfiguration().orientation == 1)
{
h = (int) (lay.getHeight()*0.5);
if(h == 0)
{
h = 200;
}
}
else
{
h = (int) (lay.getHeight()*0.3);
if(h == 0)
{
h = 130;
}
}
for(int i=0;i<netSal.length;i++)
{
netheight[i] = (int)((h*netSal[i])/highest);
grossheight[i] = (int)((h*grossSal[i])/highest);
System.out.println("net width[i] "+netheight[i]+"gross width[i] "+grossheight[i]);
}
listview.setAdapter(new bsAdapter(this,datelabel));
}
}
this is part of my xml I where I have the horizontal listview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:id="#+id/linearlay">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:gravity="center"
android:layout_gravity="center"
android:textColor="#000"
android:text="Bar Chart with out any jar"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:background="#ddd"
android:orientation="horizontal">
</RelativeLayout>
<com.xera.deviceinsight.home.HorizontalListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ddd"
/>
</LinearLayout>
Try to read this article which specifies how to use an HorizontalListView.
Declare your HorizontalListView in your XML and give it an id. Then you can use your element in your java functionality.
EDIT:
Here you have a tutorial about how implement easily a HorizontalListView. If you want a more customized version, read this.
There is a third option, which is here, where you can implement all the methods of HorizontalListView and use them (like mRect, setX, setY, onClickListener...).

my UI isn't working (buttons)

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.

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);

Android ListView not being populated by custom ParseQueryAdapter

for an app I am making I am attempting to populate a listView with data obtained from parse.com using a custom parsequeryadapter subclass. Basically it just shows a blank activity when opening the activity.
Adapter code
package com.example.battlesim;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseQuery;
import com.parse.ParseQueryAdapter;
import com.parse.ParseObject;
public class LeaderboardAdapter extends ParseQueryAdapter<ParseObject> {
public Context context;
public LeaderboardAdapter(Context c) {
super(c, new ParseQueryAdapter.QueryFactory<ParseObject>(){
public ParseQuery<ParseObject> create(){
// public final ArrayList<String> leadersName;
// public final ArrayList<Integer> leadersScore;
ParseQuery<ParseObject> queryL = ParseQuery.getQuery("Character");
queryL = queryL.whereNotEqualTo("name", null);
queryL = queryL.orderByDescending("level");
queryL.setLimit(10);
try {
queryL.find();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return queryL;
// queryL.findInBackground(new FindCallback<ParseObject>() {
// public void done(List<ParseObject> scoreList, ParseException e) {
// if (e == null) {
// for(int i = 0; i < 10; i++){
// leadersName.add(scoreList.get(i).getString("name"));
// leadersScore.add(scoreList.get(i).getInt("level"));
// }
// } else {
// Log.d("level", "Error: " + e.getMessage());
// }
// }
}
});
this.context = c;
}
public View getItemView(ParseObject o, View convertView, ViewGroup parent){
View vi = convertView;
if(convertView == null) vi = View.inflate(getContext(), R.layout.board, null);
super.getItemView(o, convertView, parent);
TextView name = (TextView) vi.findViewById(R.id.name);
TextView level = (TextView) vi.findViewById(R.id.level);
name.setText(o.getString("name"));
level.setText(o.getInt("level"));
return vi;
}
}
Activity onCreate code
LeaderboardAdapter adapter = new LeaderboardAdapter(this);
adapter.loadObjects();
ListView lv = (ListView) findViewById(R.id.listView1);
lv.setAdapter(adapter);
Board.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="TextView"
android:textSize="25dip"/>
<TextView
android:id="#+id/level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="TextView"
android:textSize="25dip"/>
</RelativeLayout>
Sorry if I formatted anything oddly or forgot to include anything. I'm new to StackExchange and somewhat new to Android programming
Replace queryL.whereNotEqualTo("name", null); with queryL.whereExists("name");

Categories