- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 fragment (称为VideoCallFragment)启动时,第一个操作是向服务器(Ruby)请求数据并收集数据并填充到 ListView 。为了查看它是否完成,我制作了一个进度对话框和onPostExcute,我使用responseView.textSet(response)。然而,加载完成后数据并未填充。
但是,如果我在相同的布局中创建一个 EditText View (空的),并且如果我单击该 View (尽管我没有将此 EditText View 设为能够在此之后进行处理),则数据将被填充。但很明显,用户不会喜欢这个不必要的过程。这是由 VideoCallFragment 中 AsnyTask 和 rootView 初始化之间的延迟引起的吗?我为这种情况编写了代码。
并且对适配器(listview)也持怀疑态度,我
final ListView lv=(ListView) rootView.findViewById(R.id.listView_classroom);
CustomAdapter adapter = new CustomAdapter(getActivity(), prgmNameList, dateList, caseList);
lv.setAdapter(adapter);
adapter.notifyDatasetChanged();
其中 prgmNameList、dateList、caseList 都是我在 VideoCallFrament 类中作为变量创建的 ArrayList。
但是最后一行不起作用并显示“无法解析方法notifyDatasetChanged();所以我在这里迷失了:(
public class CustomAdapter extends BaseAdapter{
ArrayList classroom_name_result;
ArrayList date_result;
ArrayList case_result;
String [] tutor_result;
Context context;
int [] imageId;
private static LayoutInflater inflater=null;
public CustomAdapter(Activity mainActivity, ArrayList prgmNameList, ArrayList datelist, ArrayList caselist /*, int[] prgmImages*/) {
// TODO Auto-generated constructor stub
classroom_name_result= prgmNameList;
date_result = datelist;
case_result = caselist;
context=mainActivity;
inflater = ( LayoutInflater )context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return classroom_name_result.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class Holder
{
TextView tv;
TextView date;
TextView mcase;
ImageView img;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder=new Holder();
View rowView;
rowView = inflater.inflate(R.layout.program_list, null);
holder.tv=(TextView) rowView.findViewById(R.id.lesson);
holder.tv.setText(classroom_name_result.get(position).toString());
holder.date=(TextView) rowView.findViewById(R.id.date);
holder.date.setText(date_result.get(position).toString());
holder.mcase=(TextView) rowView.findViewById(R.id.course);
holder.mcase.setText(case_result.get(position).toString());
return rowView;
}
}
下面第一个是具有 fragment 的 MainActivity。名为 VideoCallFragment 的 fragment 是未正确填充的类。
public class MainActivity extends ActionBarActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks {
some variables...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainactivity2);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragmentToLaunch = getFragmentToLaunch(position);
fragmentManager.beginTransaction()
.replace(R.id.container, fragmentToLaunch)
.commit();
}
public void onSectionAttached(int number) {
switch (number) {
case CASE_SECTION_EDIT_PROFILE:
mTitle = getString(R.string.title_section1);
break;
case CASE_SECTION_VIDEO_CALL:
mTitle = getString(R.string.title_section2);
break;
default:
break;
}
}
public void restoreActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
getMenuInflater().inflate(R.menu.main, menu);
restoreActionBar();
return true;
}
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_build_info) {
String versionInfo = "SDK Version: " + sg.com.temasys.skylink.sdk.BuildConfig.VERSION_NAME
+ "\n" + "Sample application version: " + BuildConfig.VERSION_NAME;
Log.d(TAG, versionInfo);
Toast.makeText(this, versionInfo, Toast.LENGTH_LONG).show();
return true;
}
return super.onOptionsItemSelected(item);
}
public Fragment getFragmentToLaunch(int position) {
Fragment fragmentToLaunch = null;
switch (position) {
case CASE_FRAGMENT_EDIT_PROFILE:
fragmentToLaunch = new EditProfileFragment();
break;
case CASE_FRAGMENT_VIDEO_CALL:
fragmentToLaunch = new VideoCallFragment();
break;
default:
break;
}
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, position + 1);
fragmentToLaunch.setArguments(args);
return fragmentToLaunch;
}
}
public class VideoCallFragment extends Fragment implements LifeCycleListener, MediaListener, RemotePeerListener {
some varaibles.....
private ArrayList<String> prgmNameList = new ArrayList<String>();
private ArrayList<String> caseList = new ArrayList<String>();
private ArrayList<String> dateList = new ArrayList<String>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_video_call, container, false);
parentFragment = (LinearLayout) rootView.findViewById(R.id.ll_video_call);
etRoomName = (EditText) rootView.findViewById(R.id.et_room_name);
etRoomName.setVisibility(View.GONE);
responseView = (TextView) rootView.findViewById(R.id.responseView);
SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(getContext());
String auth_token_string = settings.getString("token", ""/*default value*/);
final ListView lv=(ListView) rootView.findViewById(R.id.listView_classroom);
CustomAdapter adapter = new CustomAdapter(getActivity(), prgmNameList, dateList, caseList);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String classroom = ((TextView) view.findViewById(R.id.lesson)).getText().toString();
Toast.makeText(getActivity(), classroom, Toast.LENGTH_SHORT).show();
lv.setVisibility(View.GONE);
classroom_enter(classroom);
}
});
new soonClass().execute(auth_token_string);
return rootView;
}
class soonClass extends AsyncTask<String, String, String> {
ProgressDialog pd;
private Exception exception;
protected void onPreExecute() {
pd = new ProgressDialog(getActivity());
pd.setMessage("Logining..");
pd.show();
}
protected String doInBackground(String... args) {
String auth_token_string = args[0];
try {
URL url = new URL("url");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
/* token call */
String urlParameters = "token=" + auth_token_string ;
connection.setRequestMethod("POST");
connection.setDoOutput(true);
DataOutputStream dStream = new DataOutputStream(connection.getOutputStream());
dStream.writeBytes(urlParameters);
dStream.flush();
dStream.close();
InputStream in = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in,"iso-8859-1"),8);
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line).append("\n");
}
reader.close();
connection.disconnect();
JSONObject jsonObj = null;
jsonObj = new JSONObject(buffer.toString().trim());
/* status:ok, lessons: xxxx <-- there are two object arrays. */
JSONArray classes = null;
classes = jsonObj.getJSONArray("lessons");
// looping through All Contacts
for (int i = 0; i < classes.length(); i++) {
JSONObject c = classes.getJSONObject(i);
prgmNameList.add("lesson_" + c.getString("id"));
caseList.add(c.getString("course"));
dateList.add(c.getString("date"));
}
return "Load Complete";
}
catch(Exception e) {
Log.e("ERROR", e.getMessage(), e);
return null;
}
}
protected void onPostExecute(String response) {
if(response == null) {
response = "THERE WAS AN ERROR";
}
//progressBar.setVisibility(View.GONE);
Log.i("INFO", response);
if (pd != null) {
pd.dismiss();
}
responseView.setText(response);
}
}
public void classroom_enter(String room_name) {
somefunction();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
}
@Override
public void onResume() {
super.onResume();
SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(getContext());
String auth_token_string = settings.getString("token", ""/*default value*/);
this.onCreate(null);
}
@Override
public void onDetach() {
//close the connection when the fragment is detached, so the streams are not open.
super.onDetach();
if (skylinkConnection != null && connected) {
skylinkConnection.disconnectFromRoom();
skylinkConnection.setLifeCycleListener(null);
skylinkConnection.setMediaListener(null);
skylinkConnection.setRemotePeerListener(null);
connected = false;
audioRouter.stopAudioRouting(getActivity().getApplicationContext());
}
this.onCreate(null);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/ll_video_call"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ll_self_video"
android:orientation="horizontal"
>
<EditText
android:id="@+id/et_room_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Click to Reload"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mute_audio"
android:id="@+id/toggle_audio"
android:layout_weight="1"
android:visibility="gone"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mute_video"
android:id="@+id/toggle_video"
android:layout_weight="1"
android:visibility="gone"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/responseView" />
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView_classroom"
android:layout_gravity="center_horizontal" />
</LinearLayout>
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
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=".MainActivity">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
<fragment
android:id="@+id/navigation_drawer"
android:name="com.example.sungpah.sungpahfirst.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:layout="@layout/fragment_navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>
我尝试提供尽可能详细的信息,以便其他人在答案发布后可以轻松查看和引用!请帮助我!!
最佳答案
However the final line didn't work and says "Cannot resolve method notifyDatasetChanged();
这是因为方法签名是带有大写 S 的 notifyDataSetChanged()
。
However the data was not populated after loading is done.
这是因为适配器(以及 ListView
)不知道其数据已更新。
为您的 VideoCallFragment
提供对适配器的引用:
private CustomAdapter adapter;
设置此适配器引用
final ListView lv=(ListView) rootView.findViewById(R.id.listView_classroom);
adapter = new CustomAdapter(getActivity(), prgmNameList, dateList, caseList);
lv.setAdapter(adapter);
加载所有数据后,在 AsyncTask
中的适配器上调用 notifyDataSetChanged()
:
// looping through All Contacts
for (int i = 0; i < classes.length(); i++) {
JSONObject c = classes.getJSONObject(i);
prgmNameList.add("lesson_" + c.getString("id"));
caseList.add(c.getString("course"));
dateList.add(c.getString("date"));
}
adapter.notifyDataSetChanged();
return "Load Complete";
关于java - CustomListView未填充在Android的Fragment中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35539251/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!