在CSipSimple中添加Spinner的麻烦

时间:2015-01-08 19:14:43

标签: android web-services csip-simple

我试图在我的CSipSimple帐户注册表单中添加微调器。但我几行都有错误。 首先我

有错误
  

accountUserName =(Spinner)findViewById(" username");

findViewById未定义。 第二个是

  

ArrayAdapter dataAdapter = new ArrayAdapter(this,R.layout.spinner_item,list);

说Constructor ArrayAdapter未定义。 这个代码在一个单独的程序中工作正常但是当我试图将这个代码放在CSipsimple Basic.java文件中时,它显示了这两个错误。有人可以帮帮我吗?

public class Basic extends BaseImplementation {
protected static final String THIS_FILE = "Basic W";    

InputStream is=null;
String result=null;
String line=null;
JSONObject json = null;

private Spinner accountUserName;
private EditTextPreference accountDisplayName;
//private EditTextPreference accountUserName;
private EditTextPreference accountServer;
private EditTextPreference accountPassword;

private void bindFields() {
accountDisplayName = (EditTextPreference) findPreference("display_name");
accountUserName = (Spinner) findViewById("username");
accountServer = (EditTextPreference) findPreference("server");
accountPassword = (EditTextPreference) findPreference("password");
}

public void fillLayout(final SipProfile account) {
bindFields();

accountDisplayName.setText(account.display_name);

//fetching values fro mysql database 

String serverFull = account.reg_uri;
if (serverFull == null) {
serverFull = "";
}else {
serverFull = serverFull.replaceFirst("sip:", "");
}

ParsedSipContactInfos parsedInfo = SipUri.parseSipContact(account.acc_id);
//accountUserName.setText(parsedInfo.userName);

try
{

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.xx.xxx/conIds.php");

HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();

Log.e("Pass 1", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 1", e.toString());
Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_LONG).show();
}

try
{
BufferedReader reader = new BufferedReader
(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();

while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}

is.close();
result = sb.toString();

System.out.println(result);
Log.e("Pass 2", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 2", e.toString());
}
//
try
{
JSONArray NJA=new JSONArray(result);
String arr=NJA.getString(1);
Log.d("My arry", ""+arr);
JSONArray JA=new JSONArray(arr);

final String[] str2 = new String[JA.length()];
for(int i=0;i<JA.length();i++)
{

str2[i] = JA.getString(i);
}

List<String> list = new ArrayList<String>();

for(int i=0;i<str2.length;i++)
{
list.add(str2[i]);

}

Collections.sort(list);

ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
accountUserName.setAdapter(dataAdapter);

accountUserName.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0, View arg1,int position, long id)
{
// TODO Auto-generated method stub

String Item=accountUserName.getSelectedItem().toString();

Toast.makeText(getApplicationContext(), Item,Toast.LENGTH_LONG).show();

}

public void onNothingSelected(AdapterView<?> arg0)
{
// TODO Auto-generated method stub
}
});
}
catch(Exception e)
{

Log.e("Fail 3", e.toString());
}

accountServer.setText(serverFull);
accountPassword.setText(account.data);
}

1 个答案:

答案 0 :(得分:0)

您是否导入android.app.Activity(其中findViewById(int)已定义)和android.widget.ArrayAdapter