在UI线程中使用setAdapter时,listView中的项目具有白色文本

对于另一个活动中的另一个listView,项目的文本颜色是黑色的,就像它应该是。 但是,在另一个在新线程中使用setAdapter的活动中,当创build文本颜色的新项目是白色时,我希望它变成黑色。 这里是布局和Java代码的内容:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="project.yemeb.Search" android:background="#ffffffff"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="100dp" android:background="@drawable/back_web" android:paddingLeft="20dp" android:paddingRight="20dp" android:id="@+id/relativeLayout" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Search" android:id="@+id/button2" android:background="#ffffffff" android:onClick="onBtnClick" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/editText" android:layout_alignBottom="@+id/button2" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:background="#ffffffff" android:layout_toLeftOf="@+id/button2" android:layout_toStartOf="@+id/button2" android:layout_alignTop="@+id/button2" /> </RelativeLayout> <ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/listView" android:layout_alignParentBottom="true" android:layout_below="@+id/relativeLayout" android:headerDividersEnabled="false" /> </RelativeLayout> 

Java代码:

 package project.yemeb; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; public class Search extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); Bundle bundle = getIntent().getExtras(); String message = bundle.getString("message"); ((EditText) findViewById(R.id.editText)).setText(message); final String url = "http://example.com/sql.php?keyword="+((EditText) findViewById(R.id.editText)).getText().toString()+"&mode=6"; new Thread() { @Override public void run() { try { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(new HttpGet(url)); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { response.getEntity().writeTo(out); out.close(); } catch (IOException e) { } String responseString = out.toString(); String[] list = responseString.split("\\|"); for(String f : list) { ((MyApplication)getApplication()).setSearches(f); } final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, ((MyApplication)getApplication()).getSearches()); runOnUiThread(new Runnable() { @Override public void run() { ((ListView) findViewById(R.id.listView)).setAdapter(adapter); } }); ((ListView) findViewById(R.id.listView)).setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Intent intent = new Intent(getApplicationContext(), List.class); intent.putExtra("message", ((String) ((ListView) findViewById(R.id.listView)).getItemAtPosition(arg2))); startActivity(intent); } }); //..more logic } else { //Closes the connection. try { response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } catch (IOException e) { } } } catch (ClientProtocolException e) { } catch (IOException e) { } } }.start(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.search, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } 

我如何解决这个问题? 没有发生错误。

Solutions Collecting From Web of "在UI线程中使用setAdapter时,listView中的项目具有白色文本"