Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android-从listview向微调器添加项目_Java_Android_Android Sqlite - Fatal编程技术网

Java Android-从listview向微调器添加项目

Java Android-从listview向微调器添加项目,java,android,android-sqlite,Java,Android,Android Sqlite,我正在尝试将列表视图中的项目添加到微调器中。我的第一个活动包含列表视图。我每次都在使用按钮,在我的活动列表视图和每一行外接程序列表视图中使用SQLite数据库插入一个新行条目。第二个活动中有一个旋转器 我想在第二个活动中将每个列表和视图项添加到微调器中 这是我的产品列表适配器类: public class Product_List_Adapter extends BaseAdapter { @SuppressWarnings("unused") priv

我正在尝试将列表视图中的项目添加到微调器中。我的第一个活动包含列表视图。我每次都在使用按钮,在我的活动列表视图和每一行外接程序列表视图中使用SQLite数据库插入一个新行条目。第二个活动中有一个旋转器

我想在第二个活动中将每个列表和视图项添加到微调器中

这是我的产品列表适配器类:

 public class Product_List_Adapter extends BaseAdapter
    {
        @SuppressWarnings("unused")
        private Context mContext;
        private ArrayList<String> Productid_ArrayList;
        private ArrayList<String> ProductName_ArrayList;
        private ArrayList<String> ProductDescription_ArrayList;


        public Product_List_Adapter(Context mContext,
                ArrayList<String> productid_ArrayList,
                ArrayList<String> productName_ArrayList,
                ArrayList<String> productDescription_ArrayList)
        {
            super();
            this.mContext = mContext;
            Productid_ArrayList = productid_ArrayList;
            ProductName_ArrayList = productName_ArrayList;
            ProductDescription_ArrayList = productDescription_ArrayList;
        }




        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return Productid_ArrayList.size();
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public View getView(int pos, View child, ViewGroup parent) {
            // TODO Auto-generated method stub
            Holder mHolder;
            LayoutInflater layoutInflater;

            if(child == null)
            {
                layoutInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                child = layoutInflater .inflate(R.layout.define_products_listrow, null);
                mHolder = new Holder();
                mHolder.txt_product_id = (TextView)child.findViewById(R.id.txt_ProductId);
                mHolder.txt_product_name = (TextView)child.findViewById(R.id.txt_ProductName);
                mHolder.txt_product_description = (TextView)child.findViewById(R.id.txt_ProductDescr);

                child.setTag(mHolder);
            }
            else
            {
                mHolder = (Holder) child.getTag();
            }

            mHolder.txt_product_id.setText(Productid_ArrayList.get(pos));
            mHolder.txt_product_name.setText(ProductName_ArrayList.get(pos));
            mHolder.txt_product_description.setText(ProductDescription_ArrayList.get(pos));

            return child;
        }

        public class Holder {
            TextView txt_product_id;
            TextView txt_product_name;
            TextView txt_product_description;
        }
    }





The ProductDefine Sctivity which is contain Listview



public class DefineProducts_Activity6 extends Activity {

    String log;
    List<String> list_Dataset;
    String[] str_Splitup1;
    String[] str_Splitup2;
    String[] str_Splitup3;

    Product_List_Adapter disadpt;
    //public ArrayAdapter<String> adapter;

    private com.db_mgmt.DbHelper mHelper;
    private SQLiteDatabase dataBase;

    private static ArrayList<String> products_Id_ArrayList = new ArrayList<String>();
    private static ArrayList<String> products_Name_ArrayList = new ArrayList<String>();
    private static ArrayList<String> products_Details_ArrayList = new ArrayList<String>();

    private ListView products_List;
    private AlertDialog.Builder build;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.define_products_listview);

        products_List = (ListView) findViewById(R.id.products_List);
        mHelper = new DbHelper(this);


        //add new record
        findViewById(R.id.btnAdd_DefineProduct).setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent i = new Intent(getApplicationContext(),
                        Add_Define_Product.class);

                i.putExtra("update", false);
                startActivity(i);

            }
        });


        //click to update data
        products_List.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {

                Intent i = new Intent(getApplicationContext(),
                        Add_Define_Product.class);
                i.putExtra("productsName", products_Name_ArrayList.get(arg2));
                i.putExtra("productsDetails", products_Details_ArrayList.get(arg2));
                i.putExtra("productsID", products_Id_ArrayList.get(arg2));
                i.putExtra("update", true);
                startActivity(i);

            }
        });


        //long click to delete data
        products_List.setOnItemLongClickListener(new OnItemLongClickListener() {

            public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                    final int arg2, long arg3) {

                build = new AlertDialog.Builder(DefineProducts_Activity6.this);
                build.setTitle("Delete " + products_Name_ArrayList.get(arg2) + " "
                        + products_Details_ArrayList.get(arg2));
                build.setMessage("Do you want to delete ?");
                build.setPositiveButton("Yes",
                        new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog,
                                    int which) {

                                Toast.makeText(
                                        getApplicationContext(),
                                        products_Name_ArrayList.get(arg2) + " "
                                                + products_Details_ArrayList.get(arg2)
                                                + " is deleted.", Toast.LENGTH_LONG).show();

                                dataBase.delete(
                                        DbHelper.TABLE_DEFINE_PRODUCT_NAME,
                                        DbHelper.KEY_ID + "="
                                                + products_Id_ArrayList.get(arg2), null);
                                displayData();
                                dialog.cancel();
                            }
                        });

                build.setNegativeButton("No",
                        new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog,
                                    int which) {
                                dialog.cancel();
                            }
                        });
                AlertDialog alert = build.create();
                alert.show();

                return true;
            }
        });
    }



    @Override
    protected void onResume() {
        displayData();
        super.onResume();
    }

    /**
     * displays data from SQLite
     */
    private void displayData() {
        dataBase = mHelper.getWritableDatabase();
        Cursor mCursor = dataBase.rawQuery("SELECT * FROM "
                + DbHelper.TABLE_DEFINE_PRODUCT_NAME, null);

        products_Id_ArrayList.clear();
        products_Name_ArrayList.clear();
        products_Details_ArrayList.clear();


        if (mCursor.moveToFirst()) 
        {
            do 
            {
                products_Id_ArrayList.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_ID)));
                products_Name_ArrayList.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_PRODUCTS_NAME)));
                products_Details_ArrayList.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_PRODUCTS_DETAILS)));

            } while (mCursor.moveToNext());
        }


        SharedPreferences spdata =
            PreferenceManager.getDefaultSharedPreferences(this);
        String strDataSet1 = spdata.getString("LISTS_ID",",");
        String strDataSet2 = spdata.getString("LISTS_NAME", "");
        String strDataSet3 = spdata.getString("LISTS_Detail", "");


        Log.e(log,strDataSet1);
        Log.e(log,strDataSet2);
        Log.e(log,strDataSet3);

        list_Dataset = Arrays.asList(strDataSet1.split(","));
        list_Dataset = Arrays.asList(strDataSet3.split(","));
        list_Dataset = Arrays.asList(strDataSet2.split(","));

        str_Splitup1 = strDataSet1.split(",");
        str_Splitup2 = strDataSet2.split(",");
        str_Splitup3 = strDataSet3.split(",");


        List<String> items1 = Arrays.asList(strDataSet1.split(","));
        List<String> items2 = Arrays.asList(strDataSet2.split(","));
        List<String> items3 = Arrays.asList(strDataSet3.split(","));

        ArrayList<String> itemsarraylist = new ArrayList<String>();

        for (int j = 0; j < items2.size(); j++)
        {
            itemsarraylist.add(j, items2.get(j));

        }


disadpt = new Product_List_Adapter(DefineProducts_Activity6.this,products_Id_ArrayList, products_Name_ArrayList, products_Details_ArrayList);
        products_List.setAdapter(disadpt);
        disadpt.notifyDataSetChanged();
        mCursor.close();
    }



}
公共类产品\u列表\u适配器扩展BaseAdapter
{
@抑制警告(“未使用”)
私有上下文;
私有ArrayList Productid_ArrayList;
私有ArrayList ProductName\u ArrayList;
私有ArrayList ProductDescription_ArrayList;
公共产品列表适配器(上下文mContext,
ArrayList productid\u ArrayList,
ArrayList产品名称\u ArrayList,
ArrayList产品描述(U ArrayList)
{
超级();
this.mContext=mContext;
Productid\u ArrayList=Productid\u ArrayList;
ProductName\u ArrayList=ProductName\u ArrayList;
ProductDescription\u ArrayList=ProductDescription\u ArrayList;
}
@凌驾
public int getCount(){
//TODO自动生成的方法存根
返回Productid_ArrayList.size();
}
@凌驾
公共对象getItem(int位置){
//TODO自动生成的方法存根
返回位置;
}
@凌驾
公共长getItemId(int位置){
//TODO自动生成的方法存根
返回位置;
}
@凌驾
公共视图getView(内部位置、视图子级、视图组父级){
//TODO自动生成的方法存根
持有人mHolder;
LayoutInflater LayoutInflater;
if(child==null)
{
layoutInflater=(layoutInflater)mContext.getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);
child=layoutInflater.flate(R.layout.define\u products\u listrow,null);
mHolder=新支架();
mHolder.txt_product_id=(TextView)child.findviewbyd(R.id.txt_ProductId);
mHolder.txt\u product\u name=(TextView)child.findviewbyd(R.id.txt\u产品名称);
mHolder.txt_product_description=(TextView)child.findviewbyd(R.id.txt_ProductDescr);
setTag(mHolder);
}
其他的
{
mHolder=(Holder)child.getTag();
}
mHolder.txt_product_id.setText(Productid_ArrayList.get(pos));
mHolder.txt_product_name.setText(ProductName_ArrayList.get(pos));
mHolder.txt_product_description.setText(ProductDescription_ArrayList.get(pos));
返回儿童;
}
公共类持有者{
TextView txt_产品_id;
TextView txt_产品名称;
TextView txt_产品描述;
}
}
ProductDefine活动包含Listview
公共类定义产品活动6扩展活动{
字符串日志;
列表数据集;
字符串[]str_Splitup1;
字符串[]str_Splitup2;
字符串[]str_Splitup3;
产品列表\u适配器禁用;
//公共阵列适配器;
私有com.db_mgmt.DbHelper mHelper;
专用数据库;
私有静态ArrayList产品\u Id\u ArrayList=new ArrayList();
私有静态ArrayList产品_Name_ArrayList=new ArrayList();
私有静态ArrayList产品\u详细信息\u ArrayList=new ArrayList();
私有ListView产品列表;
私有AlertDialog.Builder构建;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.define_products_listview);
产品列表=(ListView)findViewById(R.id.products\u列表);
mHelper=新的DbHelper(this);
//添加新记录
findviewbyd(R.id.btnAdd_DefineProduct).setOnClickListener(新的OnClickListener(){
公共void onClick(视图v){
意图i=新意图(getApplicationContext(),
添加\定义\产品类);
i、 putExtra(“更新”,false);
星触觉(i);
}
});
//单击以更新数据
产品列表.setOnItemClickListener(新的OnItemClickListener(){
公共链接(AdapterView arg0、视图arg1、内部arg2、,
长arg3){
意图i=新意图(getApplicationContext(),
添加\定义\产品类);
i、 putExtra(“productsName”,products_Name_ArrayList.get(arg2));
i、 putExtra(“productsDetails”,products_Details_ArrayList.get(arg2));
i、 putExtra(“productsID”,products_Id_ArrayList.get(arg2));
i、 putExtra(“更新”,真);
星触觉(i);
}
});
//长时间单击以删除数据
产品列表。setOnItemLongClickListener(新的OnItemLongClickListener(){
长单击(AdapterView arg0、视图arg1、,
最终整数(arg2,长arg3){
build=newalertdialog.Builder(定义产品活动6.this);
build.setTitle(“删除”+products\u Name\u ArrayList.get(arg2)+”
+products_Details_ArrayList.get(arg2));
setMessage(“是否要删除?”);
build.setPositiveButton(“是”,
新建DialogInterface.OnClickListener(){
公共void onClick(对话框接口对话框,
int(其中){
Toast.makeText(
getApplicationContext(),
产品名称数组列表。获取(arg2)+“”
ArrayList<HashMap<String, String>> rssItemList = new ArrayList<HashMap<String, String>>();  
class loadStoreItems extends AsyncTask<String, Void, ArrayList<HashMap<String, String>>> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        rssItemList.clear();
    }

    @Override
    protected ArrayList<HashMap<String, String>> doInBackground(
            String... args) {
        // updating UI from Background Thread
        FeedDBHandler rssDb = new FeedDBHandler(getApplicationContext());

        // listing all RSSItems from SQLite
        List<RSSItem> rssList = rssDb.getAllItems();

        // loop through each RSSItem
        for (int i = 0; i < rssList.size(); i++) {

            RSSItem s = rssList.get(i);

            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();

            // adding each child node to HashMap key => value

            map.put(TAG_TITLE, s.getTitle());
            map.put(TAG_LINK, s.getLink());
            map.put(TAG_CATEGORY, s.getCategory());
            map.put(TAG_DESRIPTION, s.getDescription());
            map.put(TAG_PUB_DATE, s.getPubdate());
            // adding HashList to ArrayList
            rssItemList.add(map);

        }
        return rssItemList;
    }
    class GlobalClass extends Application {
    public static List<String> myVal = new ArrayList<String>() ;
    }
    listView.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {

         String clickedvalue =(String) parent.getItemAtPosition(position); 
         myVal.add(clickedvalue);

         }
    }); 
}
    intent.putParcelableArrayListExtra( "addresses", addyExtras );