0
나는 수업이 만들고있는 게임에 대한 뉴스 피드로 ListView를 사용하는 활동을위한 해골을 만들려고하고있다.안드로이드 활동 속보
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
<ListView
android:id="@+id/news"
android:layout_width="match_parent"
android:layout_height="320dp"
>
</ListView>
<Button
android:layout_width="fill_parent"
android:layout_height="45dp"
android:text="Refresh"
android:id="@+id/bRef"
/>
내 NewsActivty.java :
이 작업에서는 는 단순히 뉴스 피드 및 새로 고침 버튼 (최신 뉴스와의 ListView를 업데이트)내 activity_news.xml있다
package com.example.mynews;
import com.example.mynews.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
public class NewsActivity extends Activity {
Button refresh;
String newsfeed [] = {"latest news", "older news"};
Intent ref = new Intent(this, NewsActivity.class);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_news);
refresh = (Button) findViewById(R.id.bRef);
ListView newsStuff = (ListView) findViewById(R.id.news);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, newsfeed);
newsStuff.setAdapter(adapter);
refresh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(ref);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.news, menu);
return true;
}
}
그리고 내 manifes t : 나는 OnClickListener를을 (추가하면 내가 조각으로 조각을 모두를 구축하고 뭔가 새로운 (레이아웃, 배열 어댑터 등) 활동을 마무리 그것을 실행
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mynews"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.mynews.NewsActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
휴식 시작 에뮬레이터는 내 새로 고침 버튼에 대해 "mynews가 불행하게도 중지되었습니다"라고 알려줍니다). 내가하려는 일을 성취 할 수있는 더 좋은 방법이있을 것이라고 확신하지만, 지금까지 내가 가진 것에 대한 어떤 도움도 크게 감사 할 것입니다.
왜 오류가 발생했는지 이해하려면 오류 로그를보십시오. 다음 명령을 터미널/cmd에 써서 로그를 찾을 수 있습니다. >> adb logcat * : E – Sharj
listView를 새로 고치려고하십니까? – NickF
Sharj에는 logcat에는 아무 것도 없습니다. @NickF 예, 본질적으로. 그러나 우리가 할 계획은 목록 뷰에 항목이 표시 될 때 문자열이 배열에 채워져서 활동이 호출 될 때입니다 (따라서 startActivity를 사용하여 현재 활동 (뉴스 피드)에서 동일한 활동으로 인해 목록보기의 항목이 다시 채워집니다. –