bottomnavigatonview Problem android studio kotlin - android-studio

Please help me
i tried everything but it didnt work

You should put your setupNavigation outside of onCreate. And correct usage of it like below:
fun setupNavigation(context: Context, bottomNavigationView: BottomNavigationView) {
bottomNavigationView.setOnItemSelectedListener(object: BottomNavigationView.OnNavigationItemSelectedListener{
override fun onNavigationItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
}
}
})
}

Related

Keyboard on view event is not working by Kotlin

Coding is easy for Keyboard event handling by Kotlin if write the following code
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
return when (keyCode) {
KeyEvent.KEYCODE_ENTER -> {
....
true
}
else -> super.onKeyUp(keyCode, event)
}
}
}
But this event is working for real keyboard device not virtual keyboard on view
Let me know fix way someone....
Omg, I mistook use TextInputLayout not EditText...
Oops, sorry
I fixed the issue

Invisible mode in Android studio (kotlin)

I'm working on a news app and I want my layout to become invisible when a user saves an article. Can anyone please tell me the right way to write this code?
2 things to note:
-when I run the app,the layout is visible in the "saved fragment"
but then when I add "hideSavedMessage" right next to the code that updates the recyclerView and I run the app, the layout becomes invisible.
I want the layout to be invisible only when the user saves an article.
PS: I know how the visible and invisible mode works. I have used it before. My major problem is not knowing the right place to write the code. And by layout, I mean the text view and image view that appears on the screen. I would appreciate any contributions. Thank you.
Here's my code
class SavedFragment : Fragment(R.layout.fragment_saved) {
lateinit var viewModel: NewsViewModel
lateinit var newsAdapter: SavedAdapter
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel = (activity as NewsActivity).viewModel
setupRecyclerView()
newsAdapter.setOnItemClickListener {
val bundle = Bundle().apply {
putSerializable("article", it)
}
findNavController().navigate(
R.id.action_savedFragment_to_savedArticleFragment,
bundle
)
}
val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(
ItemTouchHelper.UP or ItemTouchHelper.DOWN,
ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT
) {
override fun onMove(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder
): Boolean {
return true
}
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
val position =
viewHolder.adapterPosition//get position of item we deleted so that we swipe to left or right
val article =
newsAdapter.differ.currentList[position]//from news adapter at the index of the position
viewModel.deleteArticle(article)
Snackbar.make(view, "Successfully deleted article", Snackbar.LENGTH_LONG)
.apply {
setAction("Undo") {
viewModel.saveArticle(article); hideSavedMessage()
}
show()
}
val isAtLastItem = position <= 0
val shouldUpdateLayout = isAtLastItem
if (shouldUpdateLayout) {
showSavedMessage()
}
}
}
ItemTouchHelper(itemTouchHelperCallback).apply {
attachToRecyclerView(rvSavedNews)
}
viewModel.getSavedNews().observe(viewLifecycleOwner, Observer { articles ->
newsAdapter.differ.submitList(articles)
})
}
private fun setupRecyclerView() {
newsAdapter = SavedAdapter()
rvSavedNews.apply {
adapter = newsAdapter
layoutManager = LinearLayoutManager(activity)
}
}
private fun hideSavedMessage() {
savedMessage.visibility = View.INVISIBLE
isArticleAdded = false
}
private fun showSavedMessage() {
savedMessage.visibility = View.VISIBLE
}
}
The problem is that code inside observer runs even at the beginning - when you run your app, right? If I understand your problem, you just have to manage to make the fun hideSavedMessage() not be running for the first time. You could for example instantiate a boolean in onCreate() and set it to false. Then, inside the observer, you could run the hideSavedMessage() only if that boolean is true - you would set it as true at the end of the observer. I hope you understand.

Fusedlocationproviderclient method getcurrentlocation() is working fine for me but

I am using the above mention method like
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
mFusedLocationClient.getCurrentLocation(LocationRequest.PRIORITY_HIGH_ACCURACY,null).addOnSuccessListener(new OnSuccessListener<Location>() {
#Override
public void onSuccess(Location location) {
if (location != null) {
userCurrentLatLng = new LatLng(location.getLatitude(), location.getLongitude());
getAddress(userCurrentLatLng);
}
}
});
in the cancellation token parameter i am passing null so is this going make any difference or i have to pass cancellation token in here. still i am getting the current location.
please suggest do i have to pass the parameter or null will be ok.
You can do like this,i have tried its working fine
`mFusedLocationClient.getCurrentLocation(
PRIORITY_HIGH_ACCURACY,
object : CancellationToken() {
override fun isCancellationRequested(): Boolean {
return false
}
override fun onCanceledRequested(onTokenCanceledListener: OnTokenCanceledListener): CancellationToken {
return this
}
}).addOnSuccessListener { location: Location ->
//handle your location here
}`

Xceed AvalonDock - Revit MainWindow.FindFirstChild returns nul

I am an Architect relatively new to C#, I am trying to implement Ehsan Iran-Nejad's amazing PyRevit coloured tabs in my own toolbar.
https://github.com/eirannejad/pyRevit/blob/12ecea9096bb649e2b6f084ba82ba1284bc78667/extensions/pyRevitTools.extension/pyRevit.tab/Toggles.panel/toggles1.stack/Tab%20Coloring.smartbutton/script.py
https://github.com/eirannejad/pyRevit/blob/12ecea9096bb649e2b6f084ba82ba1284bc78667/extensions/pyRevitTools.extension/pyRevit.tab/Toggles.panel/toggles1.stack/Tab%20Coloring.smartbutton/script.py
Unfortunately for me, this is returning null:
public static Xceed.Wpf.AvalonDock.DockingManager GetDockingManager(UIApplication uiapp)
{
var wndRoot = (MainWindow)UIAppEventUtils.GetWindowRoot(uiapp);
if (wndRoot != null)
{
return MainWindow.FindFirstChild<Xceed.Wpf.AvalonDock.DockingManager>(wndRoot);
}
return null;
}
Launched from the external command:
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class StartGroupingTabsExt : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
if(DocumentTabEventUtils.IsUpdatingDocumentTabs)
{
DocumentTabEventUtils.StopGroupingDocumentTabs();
}
else
{
DocumentTabEventUtils.StartGroupingDocumentTabs(commandData.Application);
}
return Result.Succeeded;
}
}
I cannot see quite what is going wrong, any advice would be greatly appreciated.
Cheers,
Mark
I've had something similar happening when I was building something like that. I had referenced the xceed.wpf.avalondock library from nuget and that was what caused it. Maybe you did the same thing? If I instead referenced the dll that's in the Revit installation folder, it worked without a problem.

org.eclipse.swt.browser.Browser does not open in Eclipse RAP application

Wonder if somebody can help me with this. I am trying to open an embedded browser in an Eclipse RAP applications. All examples I have seen look something like:
link.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent event) {
try {
Browser b = new Browser(parent, SWT.NONE);
b.setText("<html><body>This is Unicode HTML content from memory</body></html>");
} catch (SWTError e) {
// Error handling here
}
}
});
That doesn't do anything (visually) though. When I replace the Browser with ExternalBrowser like so:
link.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent event) {
try {
int browserStyle = ExternalBrowser.LOCATION_BAR;
ExternalBrowser.open( "myPage", "http://www.stackoverflow.com", browserStyle );
} catch (SWTError e) {
// Error handling here
}
}
});
It works. Although not exactly as desired.
I am using Eclipse RCP 1.4.2 on OS X 10.8.2.
Any insight is highly appreciated.
When you create a new widget, you have to trigger a re-layout to make it visible. Depending on your layout, it may be sufficient to call parent.layout(). If the parent is also contained in a layout and shrunken to its preferred size, you will have to call layout() on its parent. If unsure, layout the top-level shell.

Resources