Я не могу вызвать или выполнить метод insertpostion(name)
Edit question I have the following code package com.deitel.addressbook; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import java.lang.Object; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.*; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.GridLayout; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import com.deitel.addressbook.data.AddressBookDatabaseHelper; import com.deitel.addressbook.data.DatabaseDescription; import java.util.*; import java.util.List; public class AddEdit extends AppCompatActivity { private ViewPager mViewPager; private PageViewAdapter1 slider; private List<Info> informatn = new ArrayList<>(); private int current; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_edit); Toolbar tool=(Toolbar) findViewById(R.id.toolbar1); setSupportActionBar(tool); Log.d("m","addedit on create instantiated"); mViewPager=(ViewPager) findViewById(R.id.pager); slider=new PageViewAdapter1(this); if( !slider.equals(null)) Log.d("m","slider NOT null"+current); mViewPager.setAdapter(slider); Log.d("m","current inside oncreate"+current); mViewPager.setCurrentItem(current); if(mViewPager.isShown()) Log.d("m","viewpager is shown"); // load the contact // getSupportLoaderManager().initLoader(CONTACT_LOADER, null, this); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater findMenuItems = getMenuInflater(); findMenuItems.inflate(R.menu.fragment_details_menu, menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_delete: Toast.makeText(AddEdit.this,"delete ",Toast.LENGTH_LONG).show(); break; case R.id.action_edit: finish(); break; } return super.onOptionsItemSelected(item); } public class PageViewAdapter1 extends PagerAdapter { private Context mcontext; public String mname=getIntent().getStringExtra("contact"); List<Info> informatn = new ArrayList<>(); private SQLiteDatabase mDatabase; public PageViewAdapter1(Context context) { this.mcontext = context; Log.d("m","adapter called"); Log.d("m","name"+" "+mname); informatn=getInfos(); Collections.sort(informatn,new MyCompName()); insertPostion(mname); } @Override public int getCount() { return informatn.size(); } @Override public boolean isViewFromObject(View view, Object object) { return (view==(View) object); } @Override public Object instantiateItem(ViewGroup container, int position) { LayoutInflater mInflater=(LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View item_view=mInflater.inflate(R.layout.detail,container,false); try { Log.d("m","instantiateItem"); TextView nameTextView; // displays contact's name TextView phoneTextView; // displays contact's phone TextView emailTextView; // displays contact's email TextView streetTextView; // displays contact's street TextView cityTextView; // displays contact's city TextView stateTextView; // displays contact's state TextView zipTextView; // displays contact's zip // get the EditTexts nameTextView = (TextView) item_view.findViewById(R.id.nameTextView1); phoneTextView = (TextView) item_view.findViewById(R.id.phoneTextView1); emailTextView = (TextView) item_view.findViewById(R.id.emailTextView1); streetTextView = (TextView) item_view.findViewById(R.id.streetTextView1); cityTextView = (TextView) item_view.findViewById(R.id.cityTextView1); stateTextView = (TextView) item_view.findViewById(R.id.stateTextView1); zipTextView = (TextView) item_view.findViewById(R.id.zipTextView1); nameTextView.setText(informatn.get(position).name); phoneTextView.setText(informatn.get(position).phone); streetTextView.setText(informatn.get(position).street); emailTextView.setText(informatn.get(position).eamil); cityTextView.setText(informatn.get(position).City); stateTextView.setText(informatn.get(position).state); zipTextView.setText(informatn.get(position).zip); container.addView(item_view); } catch(Exception e) { e.printStackTrace(); } return item_view; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((GridLayout)object); } private ACursorWrapper queryInfo(String whereClause, String[] whereArgs){ mDatabase = new AddressBookDatabaseHelper(mcontext) .getWritableDatabase(); Cursor cursor = mDatabase.query( DatabaseDescription.Contact.TABLE_NAME, null, // columns - null selects all columns whereClause, whereArgs, null, // groupBy null, // having null // orderBy ); return new ACursorWrapper(cursor); } public List<Info> getInfos() { List<Info> information = new ArrayList<>(); ACursorWrapper cursor = queryInfo(null, null); try { cursor.moveToFirst(); while (!cursor.isAfterLast()) { information.add(cursor.getInfo()); cursor.moveToNext(); } } finally { cursor.close(); } return information; } public Info getInfo(int id) { ACursorWrapper cursor = queryInfo( DatabaseDescription.Contact._ID + " = ?", new String[] { id+"" } ); try { if (cursor.getCount() == 0) { return null; } cursor.moveToFirst(); return cursor.getInfo(); } finally { cursor.close(); } } } public void insertPostion(String name){ for(int i=0;i<informatn.size();i++){ informatn.get(i).current=i; Log.d("m","indexes"+i); } for(int i=0;i<informatn.size();i++){ Log.d("m","current"+i); if(informatn.get(i).name.equals(name)) { current = i; break; } } } class MyCompName implements Comparator<Object> { // eclipse ask for casting object public int compare(Object emp1, Object emp2) { String emp1Name = ((Info) emp1).name; String emp2Name = ((Info) emp2).name; return emp1Name.compareTo(emp2Name); //return (int)((emp2Name*100) - (emp1Name*100.0)); } } }
Что я уже пробовал:
Я пытаюсь вызвать метод insertPostion(name) в конструкторе PageViewAdapter1 любой, у кого есть какая-либо причина. спасибо
David Crow
В чем именно заключается проблема? Откуда вы знаете, что это не называется?