Profile implementation in Eclipse - java

This is my Profile.java file in which i want to add the code for "item 1" that when it was clicked it must associate with my custom.java file.
package com.haider.first;
public class Profile
extends ListActivity
implements OnItemLongClickListener {
Activity activity;
//on create method
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.profile);
//Registering list for context menu
activity = this;
ListView lv = (ListView) findViewById(android.R.id.list);
registerForContextMenu(lv);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
getResources().getStringArray(R.array.profile)));
}
//this is code for create context menu
#Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
// this is code for selecting context item to perform desired actions
#Override
public boolean onContextItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()) {
case R.id.item1:
// Here i need code from which after click custom.java will be selected or choosen
case R.id.item2:
startActivity(new Intent(Profile.this, Custom.class));
return true;
default:
return super.onContextItemSelected(item);
}
}
//This is code for Enable Single CLick while opening Context Menu
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
activity.openContextMenu(l);
super.onListItemClick(l, v, position, id);
}
//This code disbale long click
#Override
public boolean onItemLongClick(AdapterView<?> enter code here parent, View view, int position, long id) {
// TODO Auto-generated method stub
activity.closeContextMenu();
return false;
}
}
code for custom.java file in which all settings are implemented
public class Custom
extends Activity {
private SeekBar mediaVlmSeekBar = null;
private AudioManager audioManager = null;
//Oncreate Method
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
setContentView(R.layout.custom_sett);
initControls();
// Code for vibration but my app vibrates after short time intervals even it is closed
ToggleButton tb = (ToggleButton) findViewById(R.id.toggleButton1);
tb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//this method is for changing status of mutiple options.
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked) {
Intent vibintent = new Intent(getApplicationContext(), Vibration.class);
startService(vibintent);
} else {
}
}
});
//Code for Controlling Volume, here i am facing issue that i cannot change volume of my app with device buttons
/Here is my code for Volume
private void initControls () {
// TODO Auto-generated method stub
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mediaVlmSeekBar = (SeekBar) findViewById(R.id.seekBar1);
mediaVlmSeekBar.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
//Set the progress with current Media Volume
mediaVlmSeekBar.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
try {
mediaVlmSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar arg0) {
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
..........
Now my problem is when user will select item 1 named "General" it would select custom.java file without opening. In other words , when user select General the whole settings for volume, vibration, ringtone etc will be automatically selected.

Related

How to Keep Highlighted ListView Item and Its Status in the Contextual Action Bar during Device Orientation Change

I have a listview implemented with its choice mode set to CHOICE_MODE_MULTIPLE_MODAL. Here is some of the code:
listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {
private int check = 0;
#Override
public boolean onPrepareActionMode(ActionMode arg0, Menu arg1) {
// TODO Auto-generated method stub
return false;
}
#Override
public void onDestroyActionMode(ActionMode arg0) {
// TODO Auto-generated method stub
adapter.clearSelection();
}
#Override
public boolean onCreateActionMode(ActionMode arg0, Menu arg1) {
// TODO Auto-generated method stub
check = 0;
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, arg1);
return true;
}
#Override
public boolean onActionItemClicked(final ActionMode arg0,
MenuItem arg1) {
// TODO Auto-generated method stub
if ((PinPad.mMediaPlayer != null)
&& (!PinPad.mMediaPlayer.isPlaying())) {
switch (arg1.getItemId()) {
case R.id.item_delete:
LayoutInflater inflater = getLayoutInflater();
View dialogLayout = inflater.inflate(
R.layout.delete_confirmation, null);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
MainListActivity.this);
alertDialogBuilder.setView(dialogLayout);
final AlertDialog confirmationDialog = alertDialogBuilder
.create();
confirmationDialog.show();
Button buttonNo = (Button) dialogLayout
.findViewById(R.id.buttonNo);
Button buttonYes = (Button) dialogLayout
.findViewById(R.id.buttonYes);
buttonNo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// TODO Auto-generated method stub
weGotTheTime.clear();
weGotTheType.clear();
weGotTheDays.clear();
weGotTheRings.clear();
weGotTheIDs.clear();
confirmationDialog.dismiss();
adapter.clearSelection();
adapter.notifyDataSetChanged();
refreshListView();
check = 0;
arg0.finish();
}
});
buttonYes
.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
databaseData.open();
databaseData.deleteEntries(
weGotTheTime, weGotTheType,
weGotTheDays);
databaseData.close();
new AlarmTask(MainListActivity.this,
weGotTheIDs, weGotTheDays,
weGotTheRings, weGotTheType,
weGotTheTime).cancelAl();
weGotTheTime.clear();
weGotTheType.clear();
weGotTheDays.clear();
weGotTheRings.clear();
weGotTheIDs.clear();
confirmationDialog.dismiss();
adapter.clearSelection();
adapter.notifyDataSetChanged();
refreshListView();
check = 0;
arg0.finish();
}
});
break;
}
return true;
} else if (PinPad.mMediaPlayer == null) {
switch (arg1.getItemId()) {
case R.id.item_delete:
LayoutInflater inflater = getLayoutInflater();
View dialogLayout = inflater.inflate(
R.layout.delete_confirmation, null);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
MainListActivity.this);
alertDialogBuilder.setView(dialogLayout);
final AlertDialog confirmationDialog = alertDialogBuilder
.create();
confirmationDialog.show();
Button buttonNo = (Button) dialogLayout
.findViewById(R.id.buttonNo);
Button buttonYes = (Button) dialogLayout
.findViewById(R.id.buttonYes);
buttonNo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// TODO Auto-generated method stub
weGotTheTime.clear();
weGotTheType.clear();
weGotTheDays.clear();
weGotTheRings.clear();
weGotTheIDs.clear();
confirmationDialog.dismiss();
adapter.clearSelection();
adapter.notifyDataSetChanged();
refreshListView();
check = 0;
arg0.finish();
}
});
buttonYes
.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
databaseData.open();
databaseData.deleteEntries(
weGotTheTime, weGotTheType,
weGotTheDays);
databaseData.close();
new AlarmTask(MainListActivity.this,
weGotTheIDs, weGotTheDays,
weGotTheRings, weGotTheType,
weGotTheTime).cancelAl();
weGotTheTime.clear();
weGotTheType.clear();
weGotTheDays.clear();
weGotTheRings.clear();
weGotTheIDs.clear();
confirmationDialog.dismiss();
adapter.clearSelection();
adapter.notifyDataSetChanged();
refreshListView();
check = 0;
arg0.finish();
}
});
break;
}
return true;
} else {
Toast.makeText(
getApplicationContext(),
"Cannot delete alarm(s). Make sure no alarm is currently ringing.",
Toast.LENGTH_SHORT).show();
adapter.clearSelection();
check = 0;
arg0.finish();
return true;
}
}
#Override
public void onItemCheckedStateChanged(ActionMode mode,
int position, long id, boolean checked) {
// TODO Auto-generated method stub
td = results.get(position).getDays();
if (checked) {
check++;
adapter.setNewSelection(position, checked);
weGotTheTime.add(results.get(position).getTime());
weGotTheType.add(results.get(position).getType());
weGotTheDays.add(results.get(position).getDays());
weGotTheIDs.add(results.get(position).getID());
weGotTheRings.add(results.get(position).getTitle());
} else {
check--;
adapter.removeSelection(position);
weGotTheTime.remove(results.get(position).getTime());
weGotTheType.remove(results.get(position).getType());
weGotTheDays.remove(results.get(position).getDays());
weGotTheIDs.remove(results.get(position).getID());
weGotTheRings.remove(results.get(position).getTitle());
}
mode.setTitle(check + " selected");
}
});
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
listView.setItemChecked(arg2, !adapter.isPositionChecked(arg2));
vibrator.vibrate(50);
return false;
}
});
This works great, long clicking a listview item highlights it and it works fine. However, once I change the device orientation from portrait to landscape and vice versa, the highlighting is gone and the Contextual Action Bar is still showing however it doesn't show anything is selected. Any help? I've tried making selectors and drawables and manually doing it that way and still no luck. I've spent weeks on this one issue and I'm wondering if somebody out there knows how to solve it.
Thanks.
See if you can using this helps:
android:configChanges="orientation|keyboardHidden"
For more info on complete implementation refer this:
http://developer.android.com/guide/topics/resources/runtime-changes.html

Issue with setting and opening fragments in Android App

I am having a issue, as my app is crashing instead of opening the fragments. I have a ListActivity, that takes you to another activity; and in that other activity, there are two fragments. The ListActivity is expecting a result from one of the fragments.
My code was working prior to adding the fragments! However the fragments are no longer showing up and the app closes...does anyone possibly know what my issue could be? And any advice on how to take this issue? I sincerely appreciate all and any help, thank you! My code is below.
The ListActivity.java:
public class LyricList extends ListActivity {
private static final int ACTIVITY_CREATE=0;
private static final int ACTIVITY_EDIT=1;
private static final int INSERT_ID = Menu.FIRST;
private static final int DELETE_ID = Menu.FIRST + 1;
private LyricsDbAdapter mDbHelper;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lyriclist);
mDbHelper = new LyricsDbAdapter(this);
mDbHelper.open();
fillData();
registerForContextMenu(getListView());
}
private void fillData() {
Cursor lyricsCursor = mDbHelper.fetchAllLyrics();
startManagingCursor(lyricsCursor);
String[] from = new String[]{LyricsDbAdapter.KEY_TITLE};
int[] to = new int[]{R.id.text1};
SimpleCursorAdapter lyrics =
new SimpleCursorAdapter(this, R.layout.lyrics_row, lyricsCursor, from, to);
setListAdapter(lyrics);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, INSERT_ID, 0, R.string.menu_insert);
return true;
}
#Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
case INSERT_ID:
createLyric();
return true;
}
return super.onMenuItemSelected(featureId, item);
}
#Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, DELETE_ID, 0, R.string.menu_delete);
}
#Override
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case DELETE_ID:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
mDbHelper.deleteLyric(info.id);
fillData();
return true;
}
return super.onContextItemSelected(item);
}
private void createLyric() {
Intent i = new Intent(this, NextActivity.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(this, NextActivity.class);
i.putExtra(LyricsDbAdapter.KEY_ROWID, id);
startActivityForResult(i, ACTIVITY_EDIT);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
fillData();
}
}
The other activity class that should be opening via the listActivity:
public class NextActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_next);
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Tab one = actionBar.newTab().setText("Lyric Editor");
Tab two = actionBar.newTab().setText("Loops");
one.setTabListener(new MyTabListener(new LyricEditorFragment()));
two.setTabListener(new MyTabListener(new LoopsFragment()));
actionBar.addTab(one);
actionBar.addTab(two);
}
public class MyTabListener implements TabListener{
Fragment fragment;
public MyTabListener(Fragment f){
fragment = f;
}
#Override
public void onTabReselected(Tab arg0, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
#Override
public void onTabSelected(Tab arg0, FragmentTransaction ft) {
// TODO Auto-generated method stub
ft.replace(R.id.frame1, fragment);
}
#Override
public void onTabUnselected(Tab arg0, FragmentTransaction ft) {
// TODO Auto-generated method stub
ft.remove(fragment);
}
}
}
Not sure if you want to see the fragment class, but here is this just incase:
public class LyricEditorFragment extends Fragment {
private EditText mTitleText;
private EditText mBodyText;
private Long mRowId;
private LyricsDbAdapter mDbHelper;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDbHelper = new LyricsDbAdapter(getActivity());
mDbHelper.open();
mTitleText = (EditText) getView().findViewById(R.id.title);
mBodyText = (EditText) getView().findViewById(R.id.body);
Button confirmButton = (Button) getView().findViewById(R.id.confirm);
mRowId = (savedInstanceState == null) ? null :
(Long) savedInstanceState.getSerializable(LyricsDbAdapter.KEY_ROWID);
if (mRowId == null) {
Bundle extras = getActivity().getIntent().getExtras();
mRowId = extras != null ? extras.getLong(LyricsDbAdapter.KEY_ROWID)
: null;
}
populateFields();
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
getActivity().setResult(Activity.RESULT_OK);
getActivity().finish();
}
});
}
private void populateFields() {
if (mRowId != null) {
Cursor lyric = mDbHelper.fetchLyric(mRowId);
getActivity().startManagingCursor(lyric);
mTitleText.setText(lyric.getString(
lyric.getColumnIndexOrThrow(LyricsDbAdapter.KEY_TITLE)));
mBodyText.setText(lyric.getString(
lyric.getColumnIndexOrThrow(LyricsDbAdapter.KEY_BODY)));
}
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
saveState();
outState.putSerializable(LyricsDbAdapter.KEY_ROWID, mRowId);
}
#Override
public void onPause() {
super.onPause();
saveState();
}
#Override
public void onResume() {
super.onResume();
populateFields();
}
private void saveState() {
String title = mTitleText.getText().toString();
String body = mBodyText.getText().toString();
if (mRowId == null) {
long id = mDbHelper.createLyric(title, body);
if (id > 0) {
mRowId = id;
}
} else {
mDbHelper.updateLyric(mRowId, title, body);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
//return super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.activity_lyriceditor, container, false);
return view;
}
}
The problem is that you are getting a View from the activity which will return null.. you need to create/inflate the view from the onCreateView..
click here and follow the steps on how to create and use a view from fragment..
Click Here

Stuck on Sliding between two activities

I stuck with the project trying to make Page Slider between two activities.
All I know that each activity independently works, but when I try to set up PageAdapter for sliding putting:
Also, I write activity in Manifest, initialize all variables from XML in Java, but the problem starts exactly at the moment when I set up onClickListener for my buttons.
LayoutInflater inflater = LayoutInflater.from(this);
List pages = new ArrayList();
View page = inflater.inflate(R.layout.photo, null);
pages.add(page);
page = inflater.inflate(R.layout.cameragrid, null);
pages.add(page);
CameraPagerAdapter pagerAdapter = new CameraPagerAdapter(pages);
ViewPager viewPager = new ViewPager(this);
viewPager.setAdapter(pagerAdapter);
viewPager.setCurrentItem(0); //view being shown firstly
setContentView(viewPager);
instead of *setContentView(R.layout.photo);* it's doesn't launch.
What did I missed? Thanks for advance.
First Activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
makeAdditionalPageSlide(); //>>> problems started here
initialize();
InputStream is = getResources().openRawResource(R.drawable.dinam);
bmp = BitmapFactory.decodeStream(is);
}
public void makeAdditionalPageSlide(){
LayoutInflater inflater = LayoutInflater.from(this);
List<View> pages = new ArrayList<View>();
View page = inflater.inflate(R.layout.photo, null);
pages.add(page);
page = inflater.inflate(R.layout.cameragrid, null);
pages.add(page);
CameraPagerAdapter pagerAdapter = new CameraPagerAdapter(pages);
ViewPager viewPager = new ViewPager(this);
viewPager.setAdapter(pagerAdapter);
viewPager.setCurrentItem(0); //view being shown firstly
setContentView(viewPager);
}
private void initialize() {
// TODO Auto-generated method stub
iv = (ImageView) findViewById (R.id.ivReturnedPic);
ib = (ImageButton) findViewById (R.id.ibTakePic);
b = (Button) findViewById(R.id.bSetWall);
b.setOnClickListener(this);
ib.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.bSetWall:
try {
getApplicationContext().setWallpaper(bmp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case R.id.ibTakePic:
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, cameraData);
break;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
Bundle extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
iv.setImageBitmap(bmp);
}
}
PageAdapter:
public class CameraPagerAdapter extends PagerAdapter {
List<View> pages = null;
public CameraPagerAdapter(List<View> pages){
this.pages = pages;
}
#Override
public Object instantiateItem(View collection, int position){
View v = pages.get(position);
((ViewPager) collection).addView(v, 0);
return v;
}
#Override
public void destroyItem(View collection, int position, Object view){
((ViewPager) collection).removeView((View) view);
}
#Override
public int getCount(){
return pages.size();
}
#Override
public boolean isViewFromObject(View view, Object object){
return view.equals(object);
}
#Override
public void finishUpdate(View arg0){
}
#Override
public void restoreState(Parcelable arg0, ClassLoader arg1){
}
#Override
public Parcelable saveState(){
return null;
}
#Override
public void startUpdate(View arg0){
}
}
the second Activity:
public class CameraGrid extends Activity implements OnItemClickListener{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.cameragrid);
GridView gv = (GridView) findViewById(R.id.cameragrid);
CameraImageAdapter ia = new CameraImageAdapter(getApplicationContext());
gv.setAdapter(ia);
//gridview.setOnItemClickListener(this);
gv.setOnItemClickListener(this);
}
public void onItemClick(AdapterView<?> arg0, View iv, int position, long id) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), ""+position, Toast.LENGTH_LONG).show();
Intent i = new Intent(getApplicationContext(),CameraImageDetails.class);
i.putExtra("id", position);
startActivity(i);
}
}
My recommendation is to make mainActivity.xml layout with placeholder for ViewPager and setContentView(R.layout.mainActivity)
Things related to content of page view u setup in PageViewAdapter.
Maybe I didn't quite understand logic u tried to do it, but it seems a bit confusing.. :S

open a menu in ListActivity with onListItemClick

I'm trying to show a menu once the user longclick an entry in my ListActivity but I cant figure it out. Unfourtenatly lists have been always a hard nut for me to crack and I'm still learning.
package android.GUI;
public class Shifts extends ListActivity implements OnClickListener,
SimpleGestureListener {
private Typeface tf = Entry.tf, tf2 = Entry.tf2;
public static int count = 1;
int dbHourTime = 0;
private SimpleGestureFilter detector;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.shifts);
detector = new SimpleGestureFilter(this, this);
DBAdapter DB = new DBAdapter(this);
DB.open();
Cursor cursor = DB.getAllShifts();
startManagingCursor(cursor);
cursor.moveToLast();
count = cursor.getPosition();
int g = count;
cursor.moveToNext();
String[] columns = new String[] { DB.KEY_DATE, DB.KEY_HOURS,
DB.KEY_DAY, DB.KEY_ROWID, DB.KEY_START, DB.KEY_END };
int[] to = new int[] { R.id.dateDisp, R.id.shiftDisp, R.id.day,
R.id.rawId, R.id.start, R.id.finish };
ListView ls = getListView();
TextView SF = (TextView) findViewById(R.id.total);
SF.setTypeface(tf);
TextView sum = (TextView)findViewById(R.id.sum);
sum.setTypeface(tf);
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
R.layout.list_entry, cursor, columns, to);
this.setListAdapter(mAdapter);
}
#Override
protected void onListItemClick(ListView ls, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(ls, v, position, id);
CharSequence text = "Clicked";
final int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(this, text, duration);
toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER, 0, 0);
toast.show();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.view_shifts_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.back:
finish();
return true;
case R.id.clear:
DBAdapter DB = new DBAdapter(this);
DB.open();
DB.deleteAll();
startActivity(getIntent());
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
#Override
public void onSwipe(int direction) {
Intent intent = new Intent();
switch (direction) {
case SimpleGestureFilter.SWIPE_RIGHT:
intent.setClass(this, Main.class);
startActivity(intent);
break;
case SimpleGestureFilter.SWIPE_LEFT:
intent.setClass(this, Entry.class);
startActivity(intent);
break;
case SimpleGestureFilter.SWIPE_DOWN:
break;
case SimpleGestureFilter.SWIPE_UP:
break;
}
}
#Override
public boolean dispatchTouchEvent(MotionEvent me) {
this.detector.onTouchEvent(me);
return super.dispatchTouchEvent(me);
}
#Override
public void onDoubleTap() {
// TODO Auto-generated method stub
}
#Override
public void onListItemClick(ListActivity l, View v, int position, long id) {
// TODO Auto-generated method stub
}
}
This needs to be outside of your onCreate():
#Override // the error is with this method decleration
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(ls, v, position, id);
}
You're creating the onListItemClick method inside the onCreate method. Move it outside the onCreate method :)

Stop animation on button click

I am setting a animation on the imageview
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
i=(ImageView)findViewById(R.id.imageView1);
d=(Button)findViewById(R.id.button1);
a=new AnimationSet(false);
ScaleAnimation s=new ScaleAnimation(0, 2, 0, 2);
TranslateAnimation t=new TranslateAnimation(0, 100, 0, 0);
a.addAnimation(s);
a.addAnimation(t);
a.setRepeatCount(0);
a.setDuration(500);
a.setFillAfter(false);
a.setInterpolator(new AccelerateDecelerateInterpolator()); i.clearAnimation();
d.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
i.clearAnimation();
}
});
i.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
i.startAnimation(a);
System.out.println("OnTouch called>>>>>>>>>>>");
return false;
}
});
}
}
now the problem is to stop the animation and restore the previous state on the button click till that time the image should stay as it is set to be in animation.
I
Hi try adding this Code
public void onClick(View v) {
// TODO Auto-generated method stub
i.clearAnimation();
a.cancel();
a.reset();
}

Categories

Resources