问题描述
我已经在操作栏上具有搜索图标,该图标在另一个活动中具有相同的代码,但在另一个活动中未显示以下代码。我在Google上进行了大量搜索,但是没有任何解决方案。
labour_list.class中的图标未显示
enter code hpackage com.example.builderpro;
public class Labour_list extends AppCompatActivity {
TextView p_title,p_address;
ImageView line;
Myviewmodel myviewmodel;
RecyclerView recyclerView;
labour_list_adaptor madaptor;
Dproject dproject;
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_labour_list);
p_address = findViewById(R.id.addressproject_text);
p_title = findViewById(R.id.projectname_text);
line = findViewById(R.id.first_line);
recyclerView = findViewById(R.id.labour_recycler);
myviewmodel = viewmodelProviders.of(this).get(Myviewmodel.class);
dproject= getIntent().getParcelableExtra("project");
int project_id=dproject.getId();
p_title.setText(dproject.getClient_Name());
p_address.setText(dproject.getLocation());
toolbar = (Toolbar) findViewById(R.id.custom_toolbar);
setSupportActionBar(toolbar);
madaptor=new labour_list_adaptor(project_id,this);
myviewmodel.GetAllLabour().observe(this,new Observer<List<Dlabour>>() {
@Override
public void onChanged(List<Dlabour> dlabours) {
madaptor.setLabour(dlabours);
}
});
buildrecyclerView();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.search_menu,menu);
MenuItem search_item= menu.findItem(R.id.search);
SearchView searchView =(SearchView) search_item.getActionView();
searchView.setonQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
madaptor.getFilter().filter(newText);
return false;
}
});
return super.onCreateOptionsMenu(menu);
}
public boolean onoptionsItemSelected(MenuItem item) {
return super.onoptionsItemSelected(item);
}
public void buildrecyclerView()
{
RecyclerView.LayoutManager layoutManager= new linearlayoutmanager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(madaptor);
madaptor.setonClickListner(new labour_list_adaptor.onClickListner() {
@Override
public void onbtnClick(Dlabour dlabour) {
Intent intent = new Intent(Labour_list.this,attendence_sheet.class );
intent.putExtra("labour",dlabour);
intent.putExtra("project_title",dproject.getClient_Name());
startActivity(intent);
}
});
}
}
以下是activity_labour_list.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
tools:context=".Labour_list">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
>
<include
android:id="@+id/include"
layout="@layout/toolbar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/projectname_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fontFamily="@font/unineue"
android:text="Project Title"
android:textColor="@color/yellow"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@+id/addressproject_text"
app:layout_constraintTop_toBottomOf="@+id/include" />
<TextView
android:id="@+id/addressproject_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/unineue"
android:text="Address"
android:textColor="@color/text"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@+id/first_line"
app:layout_constraintTop_toBottomOf="@+id/projectname_text" />
<ImageView
android:id="@+id/first_line"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:elevation="5dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/addressproject_text"
app:srcCompat="@drawable/text_viewline" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="136dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="136dp"
android:fontFamily="@font/unineue"
android:gravity="center"
android:text="Labour List"
android:textColor="@color/yellow"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/first_line" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:elevation="5dp"
app:layout_constraintEnd_toEndOf="@+id/imageView5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView5"
app:srcCompat="@drawable/text_viewline2" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:elevation="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView7"
app:srcCompat="@drawable/text_viewline2" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/unineue"
android:text="Name"
android:textColor="@color/yellow"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView4" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/unineue"
android:text="Mobile"
android:textColor="@color/yellow"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/textView6"
app:layout_constraintEnd_toStartOf="@+id/textView8"
app:layout_constraintHorizontal_bias="0.558"
app:layout_constraintStart_toEndOf="@+id/textView6"
app:layout_constraintTop_toTopOf="@+id/textView6"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:fontFamily="@font/unineue"
android:text="Attendance"
android:textColor="@color/yellow"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/textView7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/textView7"
app:layout_constraintVertical_bias="0.0" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/labour_recycler"
android:layout_width="0dp"
android:layout_height="453dp"
android:layout_marginStart="2dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="2dp"
android:padding="2dp"
android:scrollbars="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/imageView5"
app:layout_constraintTop_toBottomOf="@+id/imageView5" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
以下为search_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/search"
android:title="Search"
android:icon="@drawable/search_"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="always"
/>
</menu>
package com.example.builderpro;
public class project_list extends AppCompatActivity {
Myviewmodel myviewmodel;
List<Dproject> myprojectlist=new ArrayList<>();
Toolbar toolbar;
RecyclerView recyclerView;
MyAdaptor myAdaptor;
int project_id=0;
@Override
public boolean onKeyDown(int keyCode,KeyEvent event) {
if(keyCode== KeyEvent.KEYCODE_BACK) {
return false;
}
return super.onKeyDown(keyCode,event);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_project_list);
toolbar=(Toolbar)findViewById(R.id.custom_toolbar);
setSupportActionBar(toolbar);
int sid= getIntent().getIntExtra("supervisor_id",0);
final MyAdaptor myAdaptor1=new MyAdaptor(this,sid);
myviewmodel= viewmodelProviders.of(this).get(Myviewmodel.class);
myviewmodel.GetAllProject().observe(this,new Observer<List<Dproject>>() {
@Override
public void onChanged(List<Dproject> dprojects) {
myAdaptor.setproject(dprojects);
}
});
myAdaptor=myAdaptor1;
buildrecyclerView();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.search_menu,menu);
MenuItem menuItem=menu.findItem(R.id.search);
androidx.appcompat.widget.SearchView searchView= (androidx.appcompat.widget.SearchView)
menuItem.getActionView();
searchView.setQueryHint("Search");
searchView.setonQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
myAdaptor.getFilter().filter(newText);
return false;
}
});
getMenuInflater().inflate(R.menu.logout_menu,menu);
return super.onCreateOptionsMenu(menu);
}
public boolean onoptionsItemSelected( MenuItem item) {
if(item.getItemId()==R.id.logout)
{
SharedPreferences preferences= getSharedPreferences("checkBox",MODE_PRIVATE);
SharedPreferences.Editor editor= preferences.edit();
editor.putString("remember","false");
editor.apply();
finish();
}
return super.onoptionsItemSelected(item);
}
public void buildrecyclerView()
{
recyclerView=(RecyclerView)findViewById(R.id.recycler_view);
RecyclerView.LayoutManager layoutManager= new linearlayoutmanager(getApplicationContext());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(myAdaptor);
myAdaptor.setonItemClickListner(new MyAdaptor.OnItemClickListener() {
@Override
public void onactivityClick(int position,int btnId) {
Dproject dproject= myAdaptor.getproject(position);
if (btnId==1){
Intent intent= new Intent(project_list.this,activity.class);
intent.putExtra("project",dproject);
startActivity(intent);
}
else
{
Intent intent= new Intent(project_list.this,Labour_list.class);
intent.putExtra("project",dproject);
startActivity(intent);
}
}
});
}
}
以下是activity_project_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".project_list"
android:background="@color/background"
android:orientation="vertical"
android:paddingBottom="20dp">
<include layout="@layout/toolbar"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recycler_view"
android:scrollbars="vertical"
/>
</LinearLayout>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)