- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个像 Facebook 一样的页面时间线(有 EditText 和 Button),它有 2 个异步任务。第一个用于向远程服务器发送参数,第二个用于从 URL 加载数据 json。实际上第一次,程序将异步加载 ListView 上的 JSON,然后如果我想在单击按钮后更新状态,那么它将插入到远程服务器上的表中。他们都成功地工作。但我有一个小问题:点击按钮(更新状态)后我想刷新我的 ListView 。我在事件单击按钮上添加了代码,然后添加了 onPostExecute(类 TheTask)。发送参数后,listview 不再重新加载内容。有人可以帮我解决这个问题吗?
我的源代码:
public class Timeline extends Activity {
private static String BaseUrl="";
private String status;
final int PROGRESS_DIALOG=1;
private ProgressBar pb;
ViewConnection connection;
ArrayList<URLPostClass> timelinelist=new ArrayList<URLPostClass>();
ArrayList<URLPostClass> arrtimeline=new ArrayList<URLPostClass>();
//ArrayList<String> arritemcategory;
ListView listview;
//ListViewAdapter ListViewAdapter;
@Override
protected Dialog onCreateDialog(int id) {
switch(id)
{
case PROGRESS_DIALOG:
ProgressDialog progress =new ProgressDialog(this);
progress.setMessage("Loading");
progress.setTitle("Memuat status");
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progress.setProgress(0);
progress.setMax(100);
return progress;
}
return super.onCreateDialog(id);
}
private class GetTimelineAyncTask extends AsyncTask<Hashtable<String,String>,Void,String> {
@Override
protected void onPreExecute() {
showDialog(PROGRESS_DIALOG);
super.onPreExecute();
}
@Override
protected String doInBackground(Hashtable<String, String>... params)
{
// TODO Auto-generated method stub
Hashtable ht=params[0];
String json=HelperHttp.getJSONResponseFromURL(BaseUrl, ht);
if(json!=null) {
parseJsonString(timelinelist,json);
}else{
return "No internet access";
}
return json;
}
protected void parseJsonString(ArrayList<URLPostClass> timelinelistjs,String json){
try {
JSONObject jsonObj = new JSONObject(json);
JSONArray array = jsonObj.getJSONArray("listtimeline");
URLPostClass.setlength(array.length());
for (int i=0;i<array.length();i++){
JSONObject js=array.getJSONObject(i);
URLPostClass timeline=new URLPostClass(js.getString("IdTimeline"),
js.getString("NamaSales"),
js.getString("JenisStatus"),
js.getString("Remark"),
js.getString("TgglInsert"),
js.getString("Path"));
timelinelistjs.add(timeline);
}
}catch (JSONException e) {
e.printStackTrace();
}
}
@Override
protected void onPostExecute(String result){
if(result=="SUCCESS")
{
}else{
DecimalFormat formatter = new DecimalFormat("#,###,###");
JSONObject jObject = null;
Context mContext = null;
try {
jObject = new JSONObject(result);
JSONArray jArray = jObject.getJSONArray("listtimeline");
for (int i=0; i < jArray.length(); i++)
{
JSONObject oneObject=jArray.getJSONObject(i);
URLPostClass timeline=new URLPostClass(oneObject.getString("IdTimeline"),
oneObject.getString("NamaSales"),
oneObject.getString("JenisStatus"),
oneObject.getString("Remark"),
oneObject.getString("TgglInsert"),
oneObject.getString("Path"));
arrtimeline.add(timeline);
}
listview = (ListView) findViewById(R.id.listtimeline);
listview.setAdapter(new ListViewTimelineAdapter(getBaseContext(), arrtimeline));
}catch (JSONException e) {
e.printStackTrace();
}
}
removeDialog(PROGRESS_DIALOG);
super.onPostExecute(result);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timeline);
Global.Timeline=this;
final RadioButton rbtnlisting=(RadioButton)findViewById(R.id.rbtnlisting);
final RadioButton rbtnclosing=(RadioButton)findViewById(R.id.rbtnclosing);
final RadioButton rbtnprospek=(RadioButton)findViewById(R.id.rbtnprospek);
final EditText edtstatus=(EditText)findViewById(R.id.edtstatus);
Button btnpost=(Button)findViewById(R.id.btnpost);
edtstatus.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
btnpost.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
rbtnlisting.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
rbtnclosing.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
rbtnprospek.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
listview = (ListView) findViewById(R.id.listtimeline);
pb=(ProgressBar)findViewById(R.id.progressBar1);
pb.setVisibility(View.GONE);
connection = new ViewConnection(getBaseContext());
if (connection.isConnectingToInternet())
{
btnpost.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (edtstatus.getText().length()>5) {
pb.setVisibility(View.VISIBLE);
TheTask async=new TheTask();
async.execute("ccc");
}else {
Toast.makeText(getBaseContext(), "Your status is too short", Toast.LENGTH_LONG).show();
}
}
});
BaseUrl="http://xxx.xxx.xxx.xxx/dummy/gettimeline.php";
executeAsyncTask();
}else {
// Internet connection is not present
LayoutInflater li = LayoutInflater.from(Timeline.this);
final View inputdialogcustom = li.inflate(R.layout.activity_confirm_connection, null);
AlertDialog.Builder alert = new AlertDialog.Builder(Timeline.this);
alert.setView(inputdialogcustom);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
System.exit(0);
}
});
alert.show();
}
}
class TheTask extends AsyncTask<String, Integer, Double>
{
@Override
protected Double doInBackground(String... params) {
postData(params[0]);
return null;
}
protected void onPostExecute(Double result) {
// TODO Auto-generated method stub
pb.setVisibility(View.GONE);
Toast.makeText(getApplicationContext(), "Status telah diposting !", Toast.LENGTH_LONG).show();
BaseUrl="http://xxx.xxx.xxx.xxx/dummy/gettimeline.php"; // I PUT ON HERE
executeAsyncTask();
}
protected void onProgressUpdate(Integer... progress){
pb.setProgress(progress[0]);
}
public void postData(String valueIWantToSend) {
// Create a new HttpClient and Post Header
RadioButton rbtnlisting=(RadioButton)findViewById(R.id.rbtnlisting);
RadioButton rbtnclosing=(RadioButton)findViewById(R.id.rbtnclosing);
RadioButton rbtnprospek=(RadioButton)findViewById(R.id.rbtnprospek);
EditText edtstatus=(EditText)findViewById(R.id.edtstatus);
if (edtstatus.getText().length()>5) {
RadioGroup radiotipe = (RadioGroup) findViewById(R.id.radiotipe);
int selectedId = radiotipe.getCheckedRadioButtonId();
RadioButton rbtnselected=(RadioButton) findViewById(selectedId);
status=rbtnselected.getText().toString();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://xxx.xxx.xxx.xxx/dummy/insert.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("idsales",OtherClass.getIdSales().toString()));
nameValuePairs.add(new BasicNameValuePair("jenis", status));
nameValuePairs.add(new BasicNameValuePair("remark", edtstatus.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("path", "coba coba"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response=httpclient.execute(httppost);
}
catch (ClientProtocolException e)
{
e.printStackTrace();
// TODO Auto-generated catch block
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}else {
Toast.makeText(getBaseContext(), "Your status is too short", Toast.LENGTH_LONG).show();
}
}
}
private void executeAsyncTask(){
Hashtable<String,String> ht=new Hashtable<String,String>();
GetTimelineAyncTask async=new GetTimelineAyncTask();
Hashtable[] ht_array={ht};
async.execute(ht_array);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.tab_sport, menu);
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.menutimeline, menu);
return super.onCreateOptionsMenu(menu);
}
@SuppressLint("NewApi")
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId())
{
case R.id.menulogout:
//Toast.makeText(getBaseContext(), "test", Toast.LENGTH_LONG).show();
//View view = item.getActionView();
//final EditText edtsearchitem=(EditText)view.findViewById(R.id.edtsearchitem);
OtherClass.setIdSales("");
Global.Timeline.finish();
Intent MyIntentDetailItem=new Intent(getBaseContext(), MainActivity.class);
startActivity(MyIntentDetailItem);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
最佳答案
在这里您必须创建全局适配器并使用适配器调用 notifydatasetchanged()
全局声明
ListViewTimelineAdapter 适配器=null;
并替换
listview = (ListView) findViewById(R.id.listtimeline);
listview.setAdapter(new ListViewTimelineAdapter(getBaseContext(), arrtimeline));
编码
listview = (ListView) findViewById(R.id.listtimeline);
adapter=new ListViewTimelineAdapter(getBaseContext(), arrtimeline);
listview.setAdapter(adapter);
adapter.NotifyDatasetChanged();
就是这样......当你想刷新列表时只需写
adapter.NotifyDatasetChanged();
并重新加载 ListView ...
关于android - 如何在 asynctask android 之后刷新 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24737311/
我的代码有问题。它总是忽略if(userDigit=1).. 谁能告诉我这里出了什么问题? for(i=0; i=1) { //
我正在尝试从字符串 html_doc 中提取 id=obj1 并尝试将 onclick 函数 附加到它 document.addEventListener("DOMContentLoaded", fu
我正在尝试使用 css 动画来动画化从一个类到另一个类的变化。基本思想是在用户单击按钮时为从一个边缘滑动到另一个边缘的 slider 设置动画。 到目前为止我的代码。 https://jsfiddle
我目前面临使用前后伪元素淡入导航项的问题。 当我悬停导航项时,它必须将其背景颜色从白色更改为蓝色。没什么疯狂的。但它也必须显示两个背景图像,分别通过将::before 伪元素从 0 更改为 1 和::
有没有简单的方法可以在最近的sqlite版本中修改表,使其与预定义的架构匹配? 架构: war_id INTEGER NOT NULL, clanname VARCHAR(64), clanhomep
我该如何将我的搜索结果变成这样的: http://i.stack.imgur.com/NfPGs.png 结果显示特定术语在单元格中的位置。 我目前有这个基本的搜索脚本: $terms =
我正在尝试使用按钮创建输入字段。但我想要的是,当创建输入字段时,我想用相同的按钮隐藏创建的输入字段。我尝试了 slideToggle 函数,但效果不是很好。 $('#addEmail').one('
我想做这样的事情: Reference of image. 我所做的:两个 UIImagesView,一个带有 UIViewContentModeLeft,另一个带有 UIViewContentMod
我在使用应该修复表中列的插入触发器时遇到了问题: id - auto increment int thread_id - int [NULL] 我想要实现的是将 thread_id 设置
我使用 tinter.after() 每 200 毫秒 刷新一次树莓派上模拟时钟的显示。一开始还可以,但逐渐地,每次刷新之间的时间达到大约 2-3 秒。是否有任何解决方案可以将刷新间隔保持在 200m
我有一个按钮,它使用::after 伪来填充背景。目前它从左到右填充,这在宽度从 0 到 100% 时有意义。但是,我希望它翻转它填充的方式。 a.project--link { margin:
我正在尝试添加带有伪元素:after的下划线来注释一些文本。 我的问题是,我想强调下划线。在此示例中,这是短语“实际上确实可以...”和“ ...不起作用”。 .test { margin-top
鉴于此: This is a test It is 有没有我可以应用到 的 CSS?那它会出现在“This is...”之前,并且在 PREVIOUS LINE 之前吗? float:left; d
我正在使用链接左侧的图像。 现在,我使用图像的::before 属性来显示,但它显示在链接的上方。 我需要对齐它。这是一张照片: Link 我使用的代码是: .vocabulary-duration
我有一个页脚有 与 6 body {background:#bbb;} .main-footer a::after { content: " | "; color: white; mar
我有一个父元素和一些子元素,但我不能直接更改它们的 CSS。所以,我试图在父元素的 CSS 中更改我 child 的 CSS。示例: .parent { & .child {
我可以 div:after { content: "hello" } 但我能否为 hello 文本添加标题,以便当我用鼠标悬停它时显示标题? 谢谢 最佳答案 你不需要伪元素: p { ba
CSS 2.1 :after 和 CSS 3 ::after 伪选择器(除了 ::after 旧浏览器不支持)?是否有任何实际理由使用更新的规范? 最佳答案 这是伪类与伪元素的区别。 除了 ::fir
「掏出钥匙开门,然后在黑暗中摸索着墙壁开关的位置,最后将室内的灯点亮。」 这是一个星期之前,我每天晚上下班回家时的固定戏码,也可能是大部分人每天回家时的经历。这种「一对一」的日常琐碎还有许多许
我正在尝试包装 , ,和具有 的元素修复我无法直接编辑的表单上的某些定位。由于某种原因,当我尝试使用以下代码时: $("label").before(""); $("input[type=tex
我是一名优秀的程序员,十分优秀!