public int getStatusBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
public int getNavigationBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
public boolean isKeyboardHidden() {
int delta = mRootView.getRootView().getHeight() - mRootView.getHeight() - getNavigationBarHeight() - getStatusBarHeight()
- getSupportActionBar().getHeight();
return delta <= 0;
}
答案 0 :(得分:0)
我已经和一些假学生一起测试了你的代码,它对我来说很好。
请通过迭代光标验证您是否正在接收学生。放一些Log.d("tag","some_student")
进行测试
此外,您应使用 YourActivityName.this 代替 getApplicationContext()。例如
tablerow = new TableRow(this);
使用虚拟学生的完整代码
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<Student> students = new ArrayList<>();
students.add(new Student("Rahul","rahul@gmail.com"));
students.add(new Student("Shweta","shweta@gmail.com"));
students.add(new Student("Test","test@gmail.com"));
students.add(new Student("Mohan","mohan@gmail.com"));
TableLayout tablelayout = new TableLayout(this);
tablelayout.setVerticalScrollBarEnabled(true);
TableRow tablerow;
TextView textview, textview1, textview3, textview5;
tablerow = new TableRow(this);
textview = new TextView(this);
textview.setText("Name");
textview.setTextColor(Color.RED);
textview.setTypeface(null, Typeface.BOLD);
textview.setPadding(20, 20, 20, 20);
tablerow.addView(textview);
textview5 = new TextView(this);
textview5.setText("Email");
textview5.setTextColor(Color.RED);
textview5.setTypeface(null, Typeface.BOLD);
textview5.setPadding(20, 20, 20, 20);
tablerow.addView(textview5);
tablelayout.addView(tablerow);
for(Integer j=0; j< students.size(); j++)
{
tablerow = new TableRow(this);
textview1 = new TextView(this);
textview1.setText(students.get(j).getName());
textview3 = new TextView(this);
textview3.setText(students.get(j).getEmail());
textview1.setPadding(20, 20, 20, 20);
textview3.setPadding(20, 20, 20, 20);
tablerow.addView(textview1);
tablerow.addView(textview3);
tablelayout.addView(tablerow);
}
setContentView(tablelayout);
}
class Student {
String name;
String email;
public Student(String name, String email) {
this.name = name;
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
}