i have a big problem. My search with UserSearchManager is working fine but i dont understand how i put the results of the search in my list view.
The result type from the search is saved at a list and i wanna take the values from the row and put the result of the row in my list View in Android, but i dont get it, how i should start?
So i hope you can help me.
Moreover a have an another problem with the Iterator.
Android Studio say it cannot resolve the problem and a cast wont help me.
Iterator<Row> it = resultData.getRows();
Row row = it.next();
Iterator iterator = row.getValues("jid");
This lines are the problem. In many other threads, people have the same code snippets and theres working, but for me not.
Here is my complete code.
package de.hsrt.campusapp.app.module.xmppchat;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Toast;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smackx.iqregister.packet.Registration;
import org.jivesoftware.smackx.search.ReportedData;
import org.jivesoftware.smackx.search.UserSearchManager;
import org.jivesoftware.smackx.xdata.Form;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import de.hsrt.campusapp.app.CampusAppConstants;
import de.hsrt.campusapp.app.R;
/**
* Created by Alexander Rein on 13.06.2016.
*/
public class ActivitySearchContact extends AppCompatActivity {
private final static String serverDomain = "search.ewcexmpp1";
private static DomainBareJid serverDomainBareJid;
private ReportedData resultData;
private ListView contactList;
private EditText contactName;
private ImageButton searchContact;
private XMPPTCPConnection con = CampusAppConstants.xmppController.getNetworkManager().getXmppTCPConnection();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_contact);
contactList = (ListView) findViewById(R.id.listViewForSearchAnswer);
contactName = (EditText) findViewById(R.id.editTextContactInput);
searchContact = (ImageButton) findViewById(R.id.btn_searchContactDetail);
searchContact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String strContact = contactName.getText().toString();
userSearch(strContact);
}
});
}
/**
* Diese Methode soll mir alle gesuchten Kontakte zurückliefern
*
* @return
*/
public ReportedData userSearch(String searchname) {
//hier eventuell die campusappconstants mit der verbindung benutzen
UserSearchManager userSearchManager = new UserSearchManager(con);
try {
Form searchForm = userSearchManager.getSearchForm(getServerDomainBareJid());
//erstellt die antwort form
Form answerForm = searchForm.createAnswerForm();
//die eigentliche suche, ich suche in der spalte Username
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", searchname);
//hier hol ich das ergebnis
this.resultData = userSearchManager.getSearchResults(answerForm, getServerDomainBareJid());
Toast.makeText(this, resultData.getRows().toString(), Toast.LENGTH_LONG).show();
if(resultData.getRows() != null)
{
Iterator<Row> it = resultData.getRows();
while(it.hasNext())
{
Row row = it.next();
Iterator iterator = row.getValues("jid");
if(iterator.hasNext())
{
String value = iterator.next().toString();
Log.i("Iteartor values......"," "+value);
}
//Log.i("Iteartor values......"," "+value);
}
Toast.makeText(this,"Username Exists",Toast.LENGTH_SHORT).show();
}
}catch(Exception e){
e.printStackTrace();
e.getMessage();
//Log.e(this.getClass().getSimpleName().toString(), "Fehler bei der Suche", e);
}
return this.resultData;
}
private static DomainBareJid getServerDomainBareJid() {
try {
serverDomainBareJid = JidCreate.domainBareFrom(serverDomain);
} catch (XmppStringprepException e) {
e.printStackTrace();
}
return serverDomainBareJid;
}
}
Aucun commentaire:
Enregistrer un commentaire