Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- */
- package com.horror.android;
- import java.io.IOException;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.Comparator;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.graphics.Color;
- import android.graphics.drawable.ColorDrawable;
- import android.os.Bundle;
- import android.util.Log;
- import android.util.SparseBooleanArray;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.View.OnClickListener;
- import android.widget.AdapterView;
- import android.widget.BaseAdapter;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.CheckedTextView;
- import android.widget.ImageView;
- import android.widget.ListAdapter;
- import android.widget.ListView;
- import android.widget.TextView;
- import android.widget.Toast;
- import android.widget.AdapterView.OnItemClickListener;
- public class BookmarksJokes extends Activity implements OnClickListener,
- OnItemClickListener {
- ListView lv;
- protected ListAdapter adapter;
- TextView title;
- ImageView img_home;
- Button btn_delete;
- public String TAG = "horror";
- private SQLiteDatabase db;
- public static final String PREFS_NAME = "MyPreferences";
- static String[] tempTitle = new String[100];
- static String[] tempBody = new String[100];
- static String[] pos = new String[100];
- private static boolean bRequiresResponse;
- private static class EfficientAdapter extends BaseAdapter {
- private LayoutInflater mInflater;
- public EfficientAdapter(Context context) {
- mInflater = LayoutInflater.from(context);
- }
- public int getCount() {
- return tempTitle.length;
- }
- public Object getItem(int position) {
- return position;
- }
- public long getItemId(int position) {
- return position;
- }
- public View getView(int position, View convertView, ViewGroup parent) {
- ViewHolder holder;
- if (convertView == null) {
- convertView = mInflater.inflate(R.layout.bookmarks_list_item,
- null);
- holder = new ViewHolder();
- holder.text1 = (TextView) convertView
- .findViewById(R.id.titleJok);
- holder.text2 = (TextView) convertView
- .findViewById(R.id.bodyJok);
- // holder.checkBox = (CheckBox)
- // convertView.findViewById(R.id.checkbox);
- holder.checkBox1 = (CheckedTextView) convertView
- .findViewById(android.R.id.checkbox);
- convertView.setTag(holder);
- } else {
- holder = (ViewHolder) convertView.getTag();
- }
- holder.text1.setText(tempTitle[position]);
- holder.text2.setText(tempBody[position]);
- // bRequiresResponse = checkBox.isChecked();
- // holder.checkBox1.setText(tempTitle[position]);
- // holder.checkBox1.setText(tempBody[position]);
- /*
- * holder.checkBox1.setTextSize(12);
- * holder.checkBox1.setTextColor(Color.YELLOW);
- */
- return convertView;
- }
- static class ViewHolder {
- TextView text1;
- TextView text2;
- CheckBox checkBox;
- private CheckedTextView checkBox1;
- }
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.bokmarksjoks);
- try {
- db = (new DatabaseHelper(this)).getWritableDatabase();
- } catch (IOException e) {
- e.printStackTrace();
- }
- setUpViews();
- title = (TextView) findViewById(R.id.body);
- SharedPreferences pref = getSharedPreferences(PREFS_NAME, 0);
- String ids = pref.getString("jid", "");
- String one = pref.getString("title", "");
- String two = pref.getString("body", "");
- tempTitle = one.split(",");
- tempBody = two.split(",");
- lv.setAdapter(new EfficientAdapter(this));
- lv.setItemsCanFocus(false);
- lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
- lv.setOnItemClickListener(this);
- ColorDrawable divcolor = new ColorDrawable(Color.WHITE);
- lv.setDivider(divcolor);
- lv.setDividerHeight(3);
- }
- private void setUpViews() {
- lv = (ListView) findViewById(R.id.list);
- img_home = (ImageView) findViewById(R.id.bmhome);
- img_home.setOnClickListener(this);
- btn_delete = (Button) findViewById(R.id.delete);
- btn_delete.setOnClickListener(this);
- // checkbox = (CheckBox) findViewById(R.id.checkbox);
- }
- private void removeJok() {
- /*
- * int pos= getIntent().getIntExtra("POSITION", 0);
- * lv.removeViewAt(pos); notifyAll();
- */
- int pos = getIntent().getIntExtra("POSITION", 0);
- /*
- * if(checkBox.isChecked()){ Log.d(TAG, " checked d]"+pos);
- * Toast.makeText(this, "checked "+pos, Toast.LENGTH_SHORT).show(); }
- */
- }
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.bmhome:
- BookmarksJokes.this.finish();
- break;
- case R.id.delete:
- AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
- alt_bld.setMessage("Are you Sure want to delete all checked jok ?")
- .setCancelable(false)
- .setPositiveButton("Yes",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog,
- int id) {
- // removeJok();
- }
- })
- .setNegativeButton("No",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog,
- int id) {
- dialog.cancel();
- }
- });
- AlertDialog alert = alt_bld.create();
- alert.setTitle("Delete Jokes");
- alert.show();
- case R.id.checkbox:
- default:
- break;
- }
- }
- public void onItemClick(AdapterView<?> arg0, View view, int position,
- long ids) {
- try {
- SparseBooleanArray sp = lv.getCheckedItemPositions();
- /*String str = "";
- for (int i = 0; i < sp.size(); i++) {
- str += tempTitle[sp.keyAt(i)] + ",";
- }*/
- Log.d(TAG, "pos " + position );
- Log.d(TAG, "str==" + str );
- System.out.println("str==" + str );
- Toast.makeText(this, "..."+str, Toast.LENGTH_SHORT).show();
- Intent intent = new Intent(BookmarksJokes.this,
- BookmarkJokesDetails.class);
- intent.putExtra("POSITION", position);
- intent.putExtra("ID", ids);
- /*Cursor cursor = (Cursor) adapter.getItem(position);
- intent.putExtra("JOK_ID",
- cursor.getInt(cursor.getColumnIndex("_id")));*/
- startActivity(intent);
- } catch (Exception e) {
- e.printStackTrace();
- }
- Toast.makeText(BookmarksJokes.this,
- "Item in position " + position + " clicked", Toast.LENGTH_LONG)
- .show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement