In Dynamic Listview row,their button functions not working
I have created an Dynamic listview,their data are coming or storing in db
part.In each row i have give some button like sms,tts,email like
that.Their content and button are displaying in my listview is showing
properly.But their button functions alone not working.Its not showing any
error also.
here i put my yourprayeractivity.java
public class YourPrayerActivity extends ListActivity implements
OnClickListener,TextToSpeech.OnInitListener {
private static final int ACTIVITY_CREATE=0;
private GinfyDbAdapter mDbHelper;
private SimpleCursorAdapter dataAdapter;
private TextToSpeech tts;
String typed;
ListView lv;
LayoutInflater inflater;
public TextView txtText;
public Button buttonsms;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_item2);
mDbHelper = new GinfyDbAdapter(this);
mDbHelper.open();
fillData();
registerForContextMenu(getListView());
}
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
private void fillData() {
mDbHelper.open();
Cursor projectsCursor = mDbHelper.fetchAllProjects();
//startManagingCursor(projectsCursor);
// Create an array to specify the fields we want to display in the
list (only TITLE)
String[] from = new
String[]{GinfyDbAdapter.CATEGORY_COLUMN_TITLE,GinfyDbAdapter.CATEGORY_COLUMN_CONTENT,GinfyDbAdapter.CATEGORY_COLUMN_COUNT};
// and an array of the fields we want to bind those fields to (in
this case just text1)
int[] to = new int[]{R.id.text2,R.id.text1,R.id.count};
dataAdapter = new SimpleCursorAdapter(
this, R.layout.activity_row2,
projectsCursor,
from,
to,
0);
setListAdapter(dataAdapter);
EditText myFilter = (EditText) findViewById(R.id.myFilter);
myFilter.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
dataAdapter.getFilter().filter(s.toString());
}
});
dataAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
return mDbHelper.fetchProjectByName(constraint.toString());
}
});
tts = new TextToSpeech(this, this);
final ListView lv = getListView();
txtText = (TextView) findViewById(R.id.text1);
lv.setTextFilterEnabled(true);
}
@Override
public void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
//btnaudioprayer.setEnabled(true);
speakOut();
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
super.onCreateOptionsMenu(menu);
MenuInflater mi = getMenuInflater();
mi.inflate(R.menu.activity_main1, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
createProject();
return super.onMenuItemSelected(featureId, item);
}
private void createProject() {
Intent i = new Intent(this, AddyourprayerActivity.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
fillData();
}
private void speakOut() {
// String text = txtText.getText().toString();
// String text = "Android speech";
tts.speak(typed, TextToSpeech.QUEUE_FLUSH, null);
}
class CustomAdapter extends SimpleCursorAdapter {
private LayoutInflater mInflater;
@SuppressWarnings("deprecation")
public CustomAdapter(Context context, int layout, Cursor c,
String[] from,
int[] to) {
super(context, layout, c, from, to);
// TODO Auto-generated constructor stub
mInflater= LayoutInflater.from(context);
}
public View getView(final int position, View convertView,
ViewGroup parent, Cursor cursor)
{
ViewHolder holder;
if(convertView==null){
convertView= mInflater.inflate(R.layout.activity_row2, null);
convertView = inflater.inflate(R.layout.activity_row2,
parent, false);
holder = new ViewHolder();
holder.tv = (TextView) convertView.findViewById(R.id.text1);
holder.tv1 = (TextView) convertView.findViewById(R.id.text2);
holder.buttonsms = (Button)
convertView.findViewById(R.id.buttonsms);
}else{
holder = (ViewHolder) convertView.getTag();
}
int col1 = cursor.getColumnIndex("title");
final String title = cursor.getString(col1 );
int col2 = cursor.getColumnIndex("content");
final String content = cursor.getString(col2 );
// TextView tv2 = (TextView) view.findViewById(R.id.text3);
//cursor.getColumnName(1)
holder.tv.setText( title);
holder.tv1.setText( content);
holder.buttonsms.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getBaseContext(), "Your answer is
correct!" , Toast.LENGTH_SHORT ).show();
}
});
// bindView(v,context,cursor);
return convertView;
}
public class ViewHolder {
TextView tv,tv1;
Button buttonsms;
}
}
public void sendsmsdata(String strContactList1) {
Intent intent3=new
Intent(YourPrayerActivity.this,SendSMSActivity.class);
intent3.putExtra("firstKeyName", strContactList1);
startActivity(intent3);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
Here for checking i have given an button sms,but while clicking the
buttonsms it has to go smsactivity but its not going to that activity.Even
for checking i puttin Toast also for button click,that toast also not
displaying.
No comments:
Post a Comment