小编And*_*ain的帖子

listview没有显示任何内容并隐藏数据

我想在列表中水平显示七个textviews和两个按钮.如果添加更多控件然后它没有显示任何内容,我的列表可以正常工作五个textviews.我的代码是正确的我试图改变xml中的所有内容,但我无法在屏幕上看到任何内容.请帮助我如何以正确的格式使用它.

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" >

 <!-- Third header line and column headings -->
 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:orientation="horizontal"
    android:background="#A1E9FF">

    <TextView android:id="@+id/column_header1"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
        />
    <TextView android:id="@+id/column_header2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />
 </LinearLayout>  

 <ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:divider="#b5b5b5"
    android:dividerHeight="2dp">
</ListView>
Run Code Online (Sandbox Code Playgroud)

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="horizontal" >

 <TextView
    android:id="@+id/plan_date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="21dp"
    android:layout_toRightOf="@+id/Plan_no"
    android:text="plan date "
    android:textColor="#000"
    android:textSize="15dp" />

 <TextView
    android:id="@+id/morn_even"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="31dp"
    android:layout_toRightOf="@+id/doc_code"
    android:text="morn_even"
    android:textColor="#000"
    android:textSize="15dp" />

 <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

xml android listview android-layout

4
推荐指数
1
解决办法
154
查看次数

如何从Android中的网络中获取时间

在我的应用程序中,我想使用网络时间而不是设备的时间.我的应用程序的要求是时间应该是正确的.

我试图从NTS服务器获得时间,但加载器继续运行并且不停止我等待超过30分钟,但我仍然没有得到任何东西.

我想知道是否有任何其他方法来获取来自网络,因为我没有从网络中获取时间花费这么多时间.

public class MainActivity extends Activity  {

public static final String TIME_SERVER = "time-a.nist.gov";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button btnGetTime = (Button)findViewById(R.id.button1);

     btnGetTime.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click 
              new GetTimeFromNetwork().execute();
        }
    });

   }

 public class GetTimeFromNetwork extends AsyncTask<String, Void, String> {

    ProgressDialog progressDialog;

    @Override
    protected void onPreExecute() {

        progressDialog = new ProgressDialog(MainActivity.this);
        progressDialog.setMessage("Loading...");
        progressDialog.setCancelable(false);
        progressDialog.show();
        Log.i( "pre execute","yes"); 

    }


    @Override
    protected String doInBackground(String... …
Run Code Online (Sandbox Code Playgroud)

java android android-networking

3
推荐指数
1
解决办法
5563
查看次数

从sqlite获取数据并在gridview中显示

我在SQLite数据库中有150条记录.我想在网格视图中显示数据库中的1行.用户将在编辑文本中输入代码,我想根据数据库中的代码选择记录并显示在网格视图中.我已经使用以下方法从数据库中获取数据,但我不知道如何在网格视图中插入值.

从SQLite获取数据的方法:

public String[][] SelectDocData( String drcode) {
 // TODO Auto-generated method stub
try {

  String arrData[][] = null; 
  SQLiteDatabase db;
  db = this.getReadableDatabase(); // Read Data
  String strSQL = "select * from table = drcode" ;
  Cursor cursor = db.rawQuery(strSQL, null);
  if(cursor != null)
  {

  if (cursor.moveToFirst()) {
  arrData = new String[cursor.getCount()][cursor.getColumnCount()];

 int i= 0;
 do {               
 arrData[i][0] = cursor.getString(0);
 arrData[i][1] = cursor.getString(1);
 arrData[i][2] = cursor.getString(2);
 i++;

} while (cursor.moveToNext());                     
}}

cursor.close();
return arrData;

} catch (Exception e) { …
Run Code Online (Sandbox Code Playgroud)

sqlite android gridview

1
推荐指数
1
解决办法
2万
查看次数

数据绑定:如何解决“找不到访问器”问题

我正在使用数据绑定库在 recyclerview 中绑定数据,但我不断收到以下错误,我不明白错误在哪里,我已经多次检查我的代码,并且我已经尝试了互联网上所有可能的解决方案,但什么也没有正在工作。请帮我解决这个问题。先感谢您。

错误

Could not find accessor com.apis.models.MoviesPageModel.movies
at android.databinding.tool.util.L.printMessage(L.java:134)
at android.databinding.tool.util.L.e(L.java:107)
Run Code Online (Sandbox Code Playgroud)

视图模型

class MoviesPageModel(private val api: ServiceApi): BaseViewModel()  {

private val _moviesList: MutableLiveData<List<Section>> = NotNullMutableLiveData(arrayListOf())
val movies: MutableLiveData<List<Section>> get() = _moviesList

fun getMovies() {
    addToDisposable(api.getMoviesRE().with()
        .doOnSubscribe {}
        .doOnSuccess {}
        .doOnError {}.subscribe({

            if(it != null){
                _moviesList.value = it.Sections
             }
        }, {
        })
    )
   }
 }
Run Code Online (Sandbox Code Playgroud)

xml

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>
    <variable
        name="vm" type="com.models.MoviesPageModel" />
</data>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui_fragments.Movies">

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        app:moviesAdapter="@{vm.movies}"
        app:viewModel="@{vm}" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

android kotlin android-databinding

1
推荐指数
1
解决办法
548
查看次数

listview中的EditText重复该值

我在列表中有三个textview和一个编辑文本.当我在edittext中输入任何值时,相同的值也会复制到另一个edittext中.我厌倦了onFocusChangedListener和onTextChanged的实现,但两种情况都是一样的.

public class ProductListAdapter extends BaseAdapter {

Context context;
public ArrayList<Products> prodList;
private static LayoutInflater inflater = null;
public ProductsList productListActivity;

public ProductListAdapter(Context context,ArrayList<Products> prodList) {
    this.context = context;
    this.prodList = prodList;
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    Log.e("In adapter", "yes");
}

@Override
public int getCount() {
    return prodList.size();
}

@Override
public Products getItem(int position) {
     return prodList.get(position); }

@Override
public long getItemId(int position) {
    return position;
}
@Override
public View getView( final int position, View convertView, ViewGroup parent) {
      Log.i(" in …
Run Code Online (Sandbox Code Playgroud)

android listview android-edittext

0
推荐指数
1
解决办法
1646
查看次数

在 0 位置添加可变列表中的项目而不覆盖第一个元素

我是 Kotlin 初学者。我有一个包含一些项目的可变列表,我想将一个新项目添加到第 0 个索引,但我的列表已经在第 0 个位置有一个项目,我想移动到第一个索引。现在我的代码正在添加该项目,但前一个项目正在丢失。

var list :MutableList<Food> = mutableListOf()
list.set(0,setItem)

fun setItem: Food{
    val food = Foood("Select", -1, "Dessert", "" )
    return food
}
Run Code Online (Sandbox Code Playgroud)

android kotlin

0
推荐指数
2
解决办法
1132
查看次数