Home > Mobile >  Help!!!!! Listview page jump page shows data problems
Help!!!!! Listview page jump page shows data problems

Time:09-19

One of my applications have a listivew list page, I want to redirect users click on the list page one, after the jump page displays the corresponding pictures and data in the database, help bosses
Page below is a list of the activity, there are some places don't understand, hope leaders can also help me and explain
/* *
* historical data the activity
*/
Public class HistoryActivity extends AppCompatActivity {

@ BindView (R.i d.l v_history)
ListView lvHistory;

List HistoryBeanList=new ArrayList<> (a);

@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Activity_history);
ButterKnife. Bind (this);
getData();
}

/* *
* obtain historical data
*/
Private void getData () {
SharedPreferences SharedPreferences=getSharedPreferences (" login ", MODE_PRIVATE);
The String url="http://" + HttpConn. IP + "/App/history/getcid";
OkHttpUtils
.get ()
Url (url)
AddParams (cid, sharedPreferences. Get string (" cid ", null))
The build ()
The execute (new StringCallback () {

@ Override
Public void one rror (Call Call, Exception e, int id) {
Toast. MakeText (HistoryActivity. This "network error", Toast. LENGTH_SHORT), show ();
The e (" LoginActivity ", "onError:" + e);
}

@ Override
Public void onResponse (String response, int id) {

Gson gson=new Gson();
History History=gson. FromJson (the response, the History class);
HistoryBeanList=history. GetHistory ();

/* *
* listview set adapter
*/
HistoryListAdapter adapter=new HistoryListAdapter (HistoryActivity. This, historyBeanList);
LvHistory. SetAdapter (adapter);

}


});
}
}

CodePudding user response:

Where are you don't understand you say first? This Activity to write very clearly,,

Is a network request data, Gson parsing, set the Adapter and the data of lvHistory,

You to see this kind of History. The data items in the class and your request is the data of the same field, maintain a consistent

The click event of the lvHistory? Jump jump when carrying data

CodePudding user response:

LvHistory. SetOnItemClickListener (new AdapterView. OnItemClickListener () {
@ Override
Public void onItemClick (AdapterView<?> The parent, View View, int position, long id) {
Intent Intent=new Intent (this, want to jump page. Class)
Intent. PutExtra (" mystring ", historyBeanList. Get (position). Get your)
Startactivity (intent);

}
});

In the page Intent Intent=getIntent ();
STR=intent. GetstringExtra (" mystring ")

CodePudding user response:

The adapter list to add events, open a new activity

CodePudding user response:

How can carry data jump

CodePudding user response:

refer to the second floor Write_BUG small expert replies:
lvHistory. The setOnItemClickListener (new AdapterView. OnItemClickListener () {
@ Override
Public void onItemClick (AdapterView<?> The parent, View View, int position, long id) {
Intent Intent=new Intent (this, want to jump page. Class)
Intent. PutExtra (" mystring ", historyBeanList. Get (position). Get your)
Startactivity (intent);

}
});

In the page Intent Intent=getIntent ();
STR=intent. GetstringExtra (" mystring ")
I did he told me that there is something wrong with the constructor
Error: the Intent (& lt; Anonymous OnItemClickListener> Class) To find appropriate constructor
Constructor Intent. The Intent (String, Uri) shall not apply to the
(parameters does not match; Cannot be converted to String)
The constructor Intent. The Intent (Context, Class<? & gt;) Does not apply to
(parameters does not match; Unable to convert the Context)

CodePudding user response:

Did you pass to HistoryListAdapter class HistoryActivity. This
HistoryListAdapter adapter=new HistoryListAdapter (HistoryActivity. This, historyBeanList);

Then public HistoryListAdapter (Context Context, List The dataList) {
Enclosing context=context//there is a context
}

Intent constructor put the context in the
Intent Intent=new Intent (context, to jump page. Class)

CodePudding user response:

reference # 6 building grass response:
did you pass to HistoryListAdapter class HistoryActivity. This
HistoryListAdapter adapter=new HistoryListAdapter (HistoryActivity. This, historyBeanList);

Then public HistoryListAdapter (Context Context, List The dataList) {
Enclosing context=context//there is a context
}

Intent constructor put the context in the
Intent Intent=new Intent (context, to jump page. Class)
error message:
Attach the relevant code:
HistoryActivity:
/* *
* historical data the activity
*/
Public class HistoryActivity extends AppCompatActivity {
Private Context Context;
@ BindView (R.i d.l v_history)
ListView lvHistory;

List HistoryBeanList=new ArrayList<> (a);

@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related